Re: Marshalling Message??
From: Stefan Höhne (do_not_use_this_adress_at_127.0.0.1)
Date: 11/11/03
- Next message: Josh Sebastian: "Re: static member function wrapper"
- Previous message: Josh Sebastian: "Re: static member function wrapper"
- In reply to: Terence: "Marshalling Message??"
- Next in thread: Martijn Lievaart: "[OT] Re: Marshalling Message??"
- Reply: Martijn Lievaart: "[OT] Re: Marshalling Message??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 11 Nov 2003 15:58:32 +0100
Hi,
"Terence" <findty@hotmail.com> wrote in message
news:0rYrb.17623$HoK.16118@news01.bloor.is.net.cable.rogers.com...
> Help Need!!!
who's 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,
8 Byte? Your're prepared for the future ...
> 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?
Depends on how you represent an 8-byte-integer in memory, thus: depends on
what
is the input.
> For Examples:
>
> Integer 1:
> 00 00 00 00 00 00 00 01 ...
>
> Integer 10:
> 00 00 00 00 00 00 00 0A ...
>
> Integer 256:
> 00 00 00 00 00 00 01 00 ...
>
> I don't want to calculate each of the byte
But: this would be the cleanest and most portable solution.
... and not that hard (if theres a shift operation on
your input) ...
#include <algorithm>
#include <iterator>
#include <iostream>
#include <iomanip>
int main() {
long long int length=266;
char message[10] = {0};
int i=9;
while ((length>0) && (i>=0)) {
message[i]=length;
length>>=8;
--i;
}
std::cout << std::hex;
std::copy(message, message+10, std::ostream_iterator<int>(std::cout, "
"));
}
Output:
0 0 0 0 0 0 0 0 1 a
> How do I put the integer in this array??
OK?
As others suggested, using standard posix functions
would be ok, too: but I doubt they'll be defined for
a 64bit integer.
HTH,
Stefan.
- Next message: Josh Sebastian: "Re: static member function wrapper"
- Previous message: Josh Sebastian: "Re: static member function wrapper"
- In reply to: Terence: "Marshalling Message??"
- Next in thread: Martijn Lievaart: "[OT] Re: Marshalling Message??"
- Reply: Martijn Lievaart: "[OT] Re: Marshalling Message??"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|