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?
 
Reply With Quote
 
 
 
 
Niels Dybdahl
Guest
Posts: n/a
 
      05-04-2005
> 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?


Most compilers will place the struct you describe in 8 bytes, but some
compilers might not.
And on some processors the most significant byte will be first (Motorola)
and on others the least significant byte will be first (Intel). So you have
to take the byte order into account, f.ex by swapping the bytes on one of
the processor types.

Niels Dybdahl


 
Reply With Quote
 
 
 
 
Uenal Mutlu
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?


homework?
it's so simple. hint: typecast adress of struct to char*, or use
union and struct and...


 
Reply With Quote
 
marbac
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?


Hello,

if you are using C++, then reinterpret_cast might be a solution.

regards marbac

 
Reply With Quote
 
=?ISO-8859-15?Q?Juli=E1n?= Albo
Guest
Posts: n/a
 
      05-04-2005
Andreas Müller wrote:

> 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?


Just use a char [8], or better, unsigned char [8] Put/get your data in it in
the format you want to use, and the code will work in all machines (in all
that use the same byte size, at least).

--
Salu2
 
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++ 1 05-04-2005 09:07 AM
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