Re: Help Needed for Marshalling Message

From: Nils Petter Vaskinn (no_at_spam.for.me.invalid)
Date: 11/11/03


Date: Tue, 11 Nov 2003 08:31:02 GMT

On Tue, 11 Nov 2003 03:06:51 +0000, Terence wrote:

> Help Need!!!
> I am writing a program for a distributed system course. I need to
> marshall all the messages in order to send them thru a socket. The first
> 8 bytes of the message are used to store the length of the message, and
> then the rest are the actual content of the message. So I have a big
> char array, what is the easiest way to store an 8-byte integer across
> the first 8 characters in the array?

That's mighty big. Will there ever be messages lager than 2^32 ? If yes it
sound's like you're doing some really heavy duty data shuffling.

This is based on the assumption that you have the same integer
representation on both ends of the wire:

/* untested and never compiled */
#include <stdint.h>

/* copy the bits of value into an array */ foo(char *array, uint64_t
value) {
  memcpy(array,&value,sizeof value);
}

-- 
NPV
"the large print giveth, and the small print taketh away"
                                Tom Waits - Step right up


Relevant Pages

  • Re: Marshalling Message??
    ... > I need to marshall all the messages in order to send them thru a socket. ... > So I have a big char array, what is the easiest way to store an 8-byte ... int main{ ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Help Needed for Marshalling Message
    ... >I need to marshall all the messages in order to send them thru a socket. ... >So I have a big char array, what is the easiest way to store an 8-byte integer ...
    (comp.lang.c)
  • Re: Showing problem
    ... >> How can i changhe this code showing how many persons i saved to the ... > better to use char array for phonenumber field too.... ... > then it will overflow and store wrong information. ... language standard) a range of values for type 'int' from ...
    (comp.lang.c)
  • istream >> (my own string class) - low-level solution?
    ... The way my Str class manages itself of course requires that the size ... of the char array to store is known when it is allocated. ... is I don't know how many characters the word I'm going to store has. ...
    (comp.lang.cpp)
  • Re: Showing problem
    ... better to use char array for phonenumber field too.... ... lets say user input something like: ... then it will overflow and store wrong information. ... you have valid data only in first record, ...
    (comp.lang.c)