By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

Forming protocol messages with structure instances

P: n/a
Two differenet applications (running on different OS, different
compilers) are communicating thru protocol consisting of functions and
arguments.
Communication link can be TCP/IP, or serial port.

What is the best way to map structure instance to protocol messages ?

The solutions we are thinking of -
1. declare each structure member as packed, and use memcpy for struct
size.
The target application should directly memcpy this area, to the
desired structure, which is already instantiated.

2. serialize each entry with member data type, followed by value, and
transmit it over link.
Value needs to be decoded using data type flag.
1st option might not be portable.
2nd option requires extra efforts and overhead.

Is there any better alternative?
regards,
Pramod
Nov 14 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
pramod wrote:
Two differenet applications (running on different OS, different
compilers) are communicating thru protocol consisting of functions and
arguments.
Communication link can be TCP/IP, or serial port.

What is the best way to map structure instance to protocol messages ?

The solutions we are thinking of -
1. declare each structure member as packed, and use memcpy for struct
size.
The target application should directly memcpy this area, to the
desired structure, which is already instantiated.
Portability problems:
Endian issues
Data type size issues (possibly less of a problem in C99)

2. serialize each entry with member data type, followed by value, and
transmit it over link.
Value needs to be decoded using data type flag.
Indeed.


1st option might not be portable.
Right.
2nd option requires extra efforts and overhead.
Also correct.
About all you can do is come up with the lightest weight
serialization/deserialization protocol (or use some third party software
to help you achieve this).

Is there any better alternative?


Not really. ;-(
Standard C is much more concerned with cross platform source
compatibility than data compatibility (at least partially due to
historical reasons).

HTH,
--ag
--
Artie Gold -- Austin, Texas
Oh, for the good old days of regular old SPAM.

Nov 14 '05 #2

P: n/a
sp********@yahoo.com (pramod) wrote:
# Two differenet applications (running on different OS, different
# compilers) are communicating thru protocol consisting of functions and
# arguments.
# Communication link can be TCP/IP, or serial port.
#
# What is the best way to map structure instance to protocol messages ?
#
# The solutions we are thinking of -
# 1. declare each structure member as packed, and use memcpy for struct
# size.
# The target application should directly memcpy this area, to the
# desired structure, which is already instantiated.

Not at all safe with different compilers.

# 2. serialize each entry with member data type, followed by value, and
# transmit it over link.
# Value needs to be decoded using data type flag.

You might want to look into ASN-1 and its encoding rules, rather than start
over from scratch. ASN software and libraries are available.

# Is there any better alternative?

If at all possible encode into an ASCII string. Much more likely to be
portable, avoids byte order problems, eases debugging, and if you redirect
traffic to a file, you can use off the shelf programming tools to look at it.
The overhead of network communications will likely overwhelm encoding
and decoding costs.

--
Derk Gwen http://derkgwen.250free.com/html/index.html
If you plan to shoplift, let us know.
Thanks
Nov 14 '05 #3

P: n/a
Derk Gwen <de******@HotPOP.com> wrote in message news:<vu************@corp.supernews.com>...

# 2. serialize each entry with member data type, followed by value, and
# transmit it over link.
# Value needs to be decoded using data type flag.

You might want to look into ASN-1 and its encoding rules, rather than start
over from scratch. ASN software and libraries are available.


FYI a lot of ASN.1 compilers and libraries are listed at
http://asn1.elibel.tm.fr/links/#tools

O. Dubuisson
Nov 14 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.