Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > protocol header

Reply
Thread Tools

protocol header

 
 
=?ISO-8859-1?Q?Andreas_M=FCller?=
Guest
Posts: n/a
 
      05-04-2005
hi @all,

I'm designing a new simple protocol and now I need a header for it.
There should only be 3 fields, one 32bit and 2 16bit fields -> 64bit
header (8byte). Due to the used library I need the data as a (unsigned
char*) for delivering. I thought about a struct to store the header but
I don't know how to cast it to the expected format for delivering.
Is there a way to store all this information and deliver it in a char[8]
which would be exactly 8byte long?

thanks,
Andreas
 
Reply With Quote
 
 
 
 
Abecedarian
Guest
Posts: n/a
 
      05-04-2005
Andreas Müller wrote:
> hi @all,
>
> I'm designing a new simple protocol and now I need a header for it.
> There should only be 3 fields, one 32bit and 2 16bit fields -> 64bit
> header (8byte). Due to the used library I need the data as a

(unsigned
> char*) for delivering. I thought about a struct to store the header

but
> I don't know how to cast it to the expected format for delivering.
> Is there a way to store all this information and deliver it in a

char[8]
> which would be exactly 8byte long?


#pragma pack(...) // see your compiler documentation for alignment

struct protocol {
int one;
short two;
short three;
};

protocol p;
// ...
char buf[8] = "";
memcpy (buf, (void*) &p, sizeof (buf));

Instead of int and short you better use the appropriate typedefs for
your platform.

::A::

 
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
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
protocol header =?ISO-8859-1?Q?Andreas_M=FCller?= C++ 4 05-04-2005 02:37 PM
Protocol Chart - Learn how to use a Protocol Analyzer news.comcast.giganews.com Wireless Networking 0 08-21-2004 04:35 PM
When i try to implement a server program giving UDP as protocol , it works fine , but if the same code is executed with TCP as protocol option, it gives an error. Tompyna Perl Misc 4 02-17-2004 06:51 PM
how to avoid using another header file inside a header file? Newsgroup - Ann C++ 4 11-02-2003 01:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57