Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] Re: For C Experts

2006-03-31 by David Hawkins

Here's a another couple of comments to provide you some context
for this type of problem, i.e., of interpreting the contents
of a binary data stream;

"Machine independent binary formats"

Not binary executable, just binary numeric representations.
There's a few out there, but here's a couple;

XDR - external data representation; used by SUNRPC.

CDR - common data representation, used by CORBA

XDR and CDR define a machine independent set of rules for
data alignment, byte packing/padding, etc.

Example: When you need to send an object/struct to another
machine, you inject all the members into a CDR byte
stream, eg.

  struct test {
   char a;
   int b;
   float c;
   double d;
  };

  cdr << test.a;
  cdr << test.b;
  cdr << test.c;
  cdr << test.d;

and the CDR layer puts appropriate padding into the block
of bytes controlled by the CDR object. You then put an endian
flag, and length parameter on that block of bytes, and
send the block across the wire. The receiving machine
reads the endian flag, then the length, and then unpacks
the structure;

  cdr >> test.a;
  cdr >> test.b;

etc.

So, if you start out knowing you are going to communicate
between different machines, its best to select a machine
independent binary protocol and then use that.

You don't have to use the C++ versions of the tools.
For microcontrollers/DSPs, I use C structures that
adhere to the alignment requirements of CDR, and
then use ACE/C++ on the Linux control host.

Cheers
Dave

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.