Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Forming protocol messages with structure instances

Reply
Thread Tools

Forming protocol messages with structure instances

 
 
pramod
Guest
Posts: n/a
 
      12-16-2003
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
 
Reply With Quote
 
 
 
 
Artie Gold
Guest
Posts: n/a
 
      12-16-2003
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.

 
Reply With Quote
 
 
 
 
Derk Gwen
Guest
Posts: n/a
 
      12-17-2003
http://www.velocityreviews.com/forums/(E-Mail Removed) (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
 
Reply With Quote
 
Olivier Dubuisson
Guest
Posts: n/a
 
      12-29-2003
Derk Gwen <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
>
> # 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dicts,instances,containers, slotted instances, et cetera. ocschwar@gmail.com Python 8 01-29-2009 09:52 AM
Re: Need help forming html+xml soap post for UPnP IGD Henry Rawas [MSFT] ASP .Net 0 09-24-2004 04:11 PM
list of class instances within a list of a class instances John Wohlbier Python 2 02-22-2004 08:41 AM
Pickle dict subclass instances using new protocol in PEP 307 Jimmy Retzlaff Python 0 10-16-2003 05:55 AM
MCSE 2003 Courses and Update Workshops now forming. Ron Williams MCSE 17 08-13-2003 02:21 PM



Advertisments