Re: [Ilugc] c/c++ endian neutral disk i/o

2010-10-07 Thread Joe Steeve
On 10/07/2010 03:02 AM, narendra babu wrote:
 1)I'm  dont need C++ Object Serialization per-se but I intend to
 write a few C structures to disk (file.bin) - The written data
 structure on-disk should be portable across different platform
 architectures (small/big endian)

Have a look at 'google protobuf' (http://code.google.com/p/protobuf/).
Store your content onto protobuf objects, serialize them onto disk and
load them back when needed.

-- 
.o. I'm a Free man. I use Free Software.
..o
ooo http://www.joesteeve.org/



signature.asc
Description: OpenPGP digital signature
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


[Ilugc] c/c++ endian neutral disk i/o

2010-10-06 Thread narendra babu
Hello all ,
 
I have 2 questions on endian neutral  : 
 
1)I'm  dont need C++ Object Serialization per-se but I intend to write a few C 
structures to disk (file.bin) -
The written data structure on-disk should be portable across different platform 
architectures (small/big endian)
 
Would someone know where I can find some library and/or sample code to write 
portable C data structure to a disk storage. 
at least some guidelines and pointers / examples would be nice.
 
2) if have solaris code which genrates binary file and i have read it from 
Linux program .
 
so any specific thing i need to take care so that i can read big endian 
generated from soalris   from Linux program which is on little endian 
 
 
Many thanks
N





___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc


Re: [Ilugc] c/c++ endian neutral disk i/o

2010-10-06 Thread Girish Venkatachalam
On Thu, Oct 7, 2010 at 3:02 AM, narendra babu cnarendra_b...@yahoo.com wrote:
 Hello all ,

 I have 2 questions on endian neutral  :

 1)I'm  dont need C++ Object Serialization per-se but I intend to write a few 
 C structures to disk (file.bin) -
 The written data structure on-disk should be portable across different 
 platform architectures (small/big endian)

If you use a character buffer C struct then it is endian neutral. Then
when you read back the structure by doing a cast using
 this code:

struct mydata *nw_struct;
  nw_struct = malloc(sizeof(mydata);
 memcpy((struct mydata *) nw_struct,
buf, sizeof(struct mydata));

  Now you can send and receive from
across the network in an Endian neutral fashion.
  If you have longs or shorts inside
the struct, just use htonl(), htons() and vice versa.

   This will surely work.

 Would someone know where I can find some library and/or sample code to write 
 portable C data structure to a disk storage.
 at least some guidelines and pointers / examples would be nice.

You have the code to achieve it.

See above.

 2) if have solaris code which genrates binary file and i have read it from 
 Linux program .


On Sparc architecture? No problem. It will work. I have done that.

 so any specific thing i need to take care so that i can read big endian 
 generated from soalris   from Linux program which is on little endian


Nothing more than what I wrote above.

Endianness does not hurt when you use unsigned char buffers.

-Girish
-- 
Gayatri Hitech

http://gayatri-hitech.com
gir...@gayatri-hitech.com
___
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc