|
|
Class data to byte stream transfer mechinisim
I'm working with a bunch of configuration data that needs to be sent over
from a workstation to a server. The old method was to simply memcpy
structures into a buffer and send that across, however now I'm trying to
use variable sized classes and coming into some difficulty in the copying
data to a bytestream without going too crazy. So I ask, what are your
experiences/suggestions/help with doing the following:
(Pointing me to other documetation, or new nifty libraries is fine)
#include <vector>
#include <memory>
class A {
public:
int aa;
int bb;
};
class B {
public:
std::vector<A*> aList;
void insert(A *element){
aList.push_back(element);
}
};
char Lan_Data[1000];
void workstation(){
A a1,a2;
B b;
a1.aa=10;a1.bb=20;
a2.aa=30;a2.bb=40;
b.insert(&a1);
b.insert(&a2);
//Now, copy data of 'b' (no matter how many elements)
//into a char buffer (Lan_Data) to send to a socket
// TBD:????
}
void server(){
B b;
//Take data from Lan_Data and load up the 'b' element.
// TBD:????
}
int main(){
memset(Lan_Data,0,sizeof(Lan_Data));
workstation();
server();
return 0;
}
|
|
0
|
|
|
|
Reply
|
me7582 (375)
|
9/24/2005 2:39:22 AM |
|
You should not use A's pointer in aList. try to define vector<A>
aList which will contain the whole object instead of obejct's pointer.
you also need to define a copy
construct function if object includes members of pointers
|
|
0
|
|
|
|
Reply
|
up3000 (4)
|
9/24/2005 3:40:06 AM
|
|
Babbit wrote:
> I'm working with a bunch of configuration data that needs to be sent over
> from a workstation to a server. The old method was to simply memcpy
> structures into a buffer and send that across, however now I'm trying to
> use variable sized classes and coming into some difficulty in the copying
> data to a bytestream without going too crazy.
this may be of interest
http://www.parashift.com/c++-faq-lite/serialization.html
--
Nick Keighley
|
|
0
|
|
|
|
Reply
|
nick_keighley_nospam (4574)
|
9/24/2005 11:55:43 AM
|
|
Babbit wrote:
> I'm working with a bunch of configuration data that needs to be sent over
> from a workstation to a server. The old method was to simply memcpy
> structures into a buffer and send that across, however now I'm trying to
> use variable sized classes and coming into some difficulty in the copying
> data to a bytestream without going too crazy. So I ask, what are your
> experiences/suggestions/help with doing the following:
> (Pointing me to other documetation, or new nifty libraries is fine)
>
>
> #include <vector>
> #include <memory>
>
> class A {
> public:
> int aa;
> int bb;
> };
>
> class B {
> public:
> std::vector<A*> aList;
> void insert(A *element){
> aList.push_back(element);
> }
> };
>
> char Lan_Data[1000];
>
> void workstation(){
> A a1,a2;
> B b;
>
> a1.aa=10;a1.bb=20;
> a2.aa=30;a2.bb=40;
>
> b.insert(&a1);
> b.insert(&a2);
>
> //Now, copy data of 'b' (no matter how many elements)
> //into a char buffer (Lan_Data) to send to a socket
>
> // TBD:????
> }
>
> void server(){
> B b;
> //Take data from Lan_Data and load up the 'b' element.
>
> // TBD:????
> }
>
> int main(){
> memset(Lan_Data,0,sizeof(Lan_Data));
> workstation();
> server();
> return 0;
> }
You could encode the structures using using BER (Binary Encoding Rules)
(see ASN.1). There are numerous implementations available.
You could also encode the structure as XML, send it over, and then
rebuild it on the other side by parsing the XML. Actually this
suggestion just repackages the first one. In both cases the receiver
would be able to recreate the original data structures, without knowing
their structure beforehand.
Greg
|
|
0
|
|
|
|
Reply
|
greghe (676)
|
9/25/2005 10:34:03 AM
|
|
|
3 Replies
31 Views
(page loaded in 0.097 seconds)
Similiar Articles: TCP MSS issue - comp.unix.programmerI_SRDOPT is an option for Streams and not for TCP. It works if a transport ... two-way connection based byte streams. An out-of-band data transmission mechanism ... BufferedReader vs NIO Buffer - comp.lang.java.programmer ...... faster than the IO BufferedReader class ... throw new IOException("Bad data read - offset " + ix + " expected " + (byte)(ix ... unless you have an automated mechanism to ... Reading Serial data through Simulink Input Packet - comp.soft-sys ...At the Simulink side,Simulink should send a byte such ... The ones that we often use are Transfer Fcn, State-space ... Help Reading Continuous Serial Port Data Stream? - comp.soft ... variant data type - comp.lang.fortran... probably pack/unpack the bits using either transfer ... WHAT KIND OF DATA TYPE ISN'T A POD: Any data object of class ... to bytes? - comp.lang.java.help However, the Byte data ... zlib and gzip - comp.compressionI get the Z_DATA_ERROW with msg ... the end of the deflate stream (i.e. the first byte of ... is possible that chunked transfer coding is being used, which breaks up the stream ... write read string data - comp.lang.java.help> import java.io.*; >=20 > public class ... Help Reading Continuous Serial Port Data Stream ... The conversion of strings from BYTE to ... Conversion of data from ... Random access to content of archived files without extraction ...(ps, you will obviously also need a mechanism to control the data ... uncompressed size s), write the s byte of uncompressed data. ... the offset s of the uncompressed data stream ... OpenGL video rendering - comp.graphics.api.openglIm able to play 2-3 video streams at ... yres, GL_BGR_EXT, GL_UNSIGNED_BYTE, Data); You can use PBO or PDR but you have to be carefull because of async image data transfer. synchronous interprocess communication - comp.unix.programmer ...... details like buffering down to a single byte ... tty/pty in "raw" mode will buffer the data. And even if those mechanisms ... communication Routing Algorithms IP Transport ... How to check whether malloc has allocated memory properly in case ...*Extended range is permitted;control may transfer into the ... computers a little (these had 3, 6, and 12-byte data ... that none of these mainframe/supercomputer class ... Class ByteArrayOutputStreampublic class ByteArrayOutputStream extends OutputStream. This class implements an output stream in which the data is written into a byte array. Data Transfer (Java Foundation Classes) - MIK telecomThe DataFlavor Class. A data transfer mechanism requires a precise and portable way to specify ... to determine whether the return value is an InputStream (a byte stream) or ... 7/6/2012 11:27:47 PM
|
|
|
|
|
|
|
|
|