Archived
This forum has been archived. Please start a new discussion on GitHub.
Zero copy streaming help please
Hi there,
I am trying to use zero copy streaming with OutputStream and InputStream but I am having trouble, so I am writing the forum to seek help please.
I am trying to use the zero copy approach from the website :
The OutputStream Interface in C++ - Ice 3.5 - ZeroC
The InputStream Interface in C++ - Ice 3.5 - ZeroC
I create an OutputStream ...
Ice::OutputStreamPtr ostreamO=createOutputStream(communicator, Ice::stringToEncodingVersion(communicator->getProperties()->getProperty("Ice.Default.EncodingVersion")));
I load up the data and send to the ostreamO :
vector<Ice::Byte> data(10); // I load chars into the data vector before sending
pair<const Ice::Byte*, const Ice::Byte*> p;
p.first=&data[0]; p.second=&data[data.size()-1];
ostreamO->write(p.first, p.second);
cout<<"pos="<<ostreamO->pos()<<endl;
it tells me : pos=10
great - it seems that the data has gone out.
I now try to read back ...
vector<Ice::Byte> data(128);
Ice::InputStreamPtr istreamI=Ice::wrapInputStream(communicator, data, Ice::stringToEncodingVersion(communicator->getProperties()->getProperty("Ice.Default.EncodingVersion")));
pair<const Ice::Byte*, const Ice::Byte*> p;
istreamI->read(p);
cout<<"readSize = "<<istreamI->readSize()<<endl;
printf("%p, %p\n",p.first,p.second);
I get :
readSizse = 0
0x141e661, 0x141e661
I use slice2cpp with the --stream option.
Any ideas what I am doing incorrectly ?
thanks
Matt
I am trying to use zero copy streaming with OutputStream and InputStream but I am having trouble, so I am writing the forum to seek help please.
I am trying to use the zero copy approach from the website :
The OutputStream Interface in C++ - Ice 3.5 - ZeroC
The InputStream Interface in C++ - Ice 3.5 - ZeroC
I create an OutputStream ...
Ice::OutputStreamPtr ostreamO=createOutputStream(communicator, Ice::stringToEncodingVersion(communicator->getProperties()->getProperty("Ice.Default.EncodingVersion")));
I load up the data and send to the ostreamO :
vector<Ice::Byte> data(10); // I load chars into the data vector before sending
pair<const Ice::Byte*, const Ice::Byte*> p;
p.first=&data[0]; p.second=&data[data.size()-1];
ostreamO->write(p.first, p.second);
cout<<"pos="<<ostreamO->pos()<<endl;
it tells me : pos=10
great - it seems that the data has gone out.
I now try to read back ...
vector<Ice::Byte> data(128);
Ice::InputStreamPtr istreamI=Ice::wrapInputStream(communicator, data, Ice::stringToEncodingVersion(communicator->getProperties()->getProperty("Ice.Default.EncodingVersion")));
pair<const Ice::Byte*, const Ice::Byte*> p;
istreamI->read(p);
cout<<"readSize = "<<istreamI->readSize()<<endl;
printf("%p, %p\n",p.first,p.second);
I get :
readSizse = 0
0x141e661, 0x141e661
I use slice2cpp with the --stream option.
Any ideas what I am doing incorrectly ?
thanks
Matt
0
Comments
-
Hi,
You need to call OutputStream::finished to retrieve the marshaled data. The marshaled data should then be passed to the createInputStream method if you want to un-marshall it.
See the demo/Ice/invoke C++ demo for an example on how to use the streaming API.
Cheers,
Benoit.0 -
Hi,
You need to call OutputStream::finished to retrieve the marshaled data. The marshaled data should then be passed to the createInputStream method if you want to un-marshall it.
See the demo/Ice/invoke C++ demo for an example on how to use the streaming API.
Cheers,
Benoit.
OK - I think I understand now, streaming is used to serialise various forms of data into a vector. This vector is passed to the proxy for de-serialisation.
Is that an OK rough description ?
Matt0 -
More or less . The streaming API is used to encode/decode Slice data types into/from a byte sequence. This byte sequence can be used either with the blobject API (proxy or servant ice_invoke methods) or for other purposes (database storage, etc). See the Dynamic Ice chapter in the manual for more information.0
-
More or less . The streaming API is used to encode/decode Slice data types into/from a byte sequence. This byte sequence can be used either with the blobject API (proxy or servant ice_invoke methods) or for other purposes (database storage, etc). See the Dynamic Ice chapter in the manual for more information.
Great! thanks for the information.
Matt0