471,325 Members | 1,685 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,325 software developers and data experts.

Convert byte stream to user defined type/class

Hi,

My application receives data from multiple sources transferred over
ethernet. This data is broken into packets of bytes before being transmitted
over the network.

My application has to take the data and arrange into a user defined
type/class.

e.g one message from source 1 may be 10-15KB. This is broken down into
smaller packets say for arguments sake 1KB.

My application then has to take each packet and construct the data back into
it's orginal size of 15KB.

This will probably be stored in some sort of array/arraylist of doubles
rather than bytes.

My question is :- what is the best/most efficient way of converting the
individual packets of bytes into an array of say doubles?

Regards
Macca

Jan 30 '06 #1
5 5423
Macca wrote:
My application receives data from multiple sources transferred over
ethernet. This data is broken into packets of bytes before being transmitted
over the network.

My application has to take the data and arrange into a user defined
type/class.

e.g one message from source 1 may be 10-15KB. This is broken down into
smaller packets say for arguments sake 1KB.

My application then has to take each packet and construct the data back into
it's orginal size of 15KB.

This will probably be stored in some sort of array/arraylist of doubles
rather than bytes.

My question is :- what is the best/most efficient way of converting the
individual packets of bytes into an array of say doubles?


It's not clear whether you're only controlling the reading side or not.
Do you get to decide how to write the data *and* how to read it, or is
the data you're reading already in a fixed format?

Jon

Jan 30 '06 #2
Hi,

"Macca" <Ma***@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
Hi,

My application receives data from multiple sources transferred over
ethernet. This data is broken into packets of bytes before being
transmitted
over the network.
The package size is (in most cases) irrelevant. The network layer is the
responsible of doing this . your app just read X amount of data.
My application has to take the data and arrange into a user defined
type/class.
Serialization could help you here.
My question is :- what is the best/most efficient way of converting the
individual packets of bytes into an array of say doubles?


If you know the size of the array you can read that amount of data in a
byte[], then using BitConverter.ToDouble ( .... ) convert each chunk to a
double.


--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Jan 30 '06 #3
First, you need to know how many bytes you expect to receive or have some
delimiter to tell you. If both sides are .Net, then the easiest way is to
use BinarySerializer to/from byte[]. It does not matter how many packets
are sent as long as you wait till you receive all bytes before the
conversion.

--
William Stacey [MVP]

"Macca" <Ma***@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
| Hi,
|
| My application receives data from multiple sources transferred over
| ethernet. This data is broken into packets of bytes before being
transmitted
| over the network.
|
| My application has to take the data and arrange into a user defined
| type/class.
|
| e.g one message from source 1 may be 10-15KB. This is broken down into
| smaller packets say for arguments sake 1KB.
|
| My application then has to take each packet and construct the data back
into
| it's orginal size of 15KB.
|
| This will probably be stored in some sort of array/arraylist of doubles
| rather than bytes.
|
| My question is :- what is the best/most efficient way of converting the
| individual packets of bytes into an array of say doubles?
|
| Regards
| Macca
|
Jan 30 '06 #4
Hi William,

Thanks for the reply. The server side is .NET but the client side is
embedded C.

I will know in advance how much data is being sent.

e.g 10 packets of 256KB which will be sent and then needs to be recompiled
into and array of doubles.

Can BinarySerializer still be used in this scenario. Is this a .NET method?

Thanks In Advance
Macca

"William Stacey [MVP]" wrote:
First, you need to know how many bytes you expect to receive or have some
delimiter to tell you. If both sides are .Net, then the easiest way is to
use BinarySerializer to/from byte[]. It does not matter how many packets
are sent as long as you wait till you receive all bytes before the
conversion.

--
William Stacey [MVP]

"Macca" <Ma***@discussions.microsoft.com> wrote in message
news:AF**********************************@microsof t.com...
| Hi,
|
| My application receives data from multiple sources transferred over
| ethernet. This data is broken into packets of bytes before being
transmitted
| over the network.
|
| My application has to take the data and arrange into a user defined
| type/class.
|
| e.g one message from source 1 may be 10-15KB. This is broken down into
| smaller packets say for arguments sake 1KB.
|
| My application then has to take each packet and construct the data back
into
| it's orginal size of 15KB.
|
| This will probably be stored in some sort of array/arraylist of doubles
| rather than bytes.
|
| My question is :- what is the best/most efficient way of converting the
| individual packets of bytes into an array of say doubles?
|
| Regards
| Macca
|

Feb 10 '06 #5
1) Get the len bytes (i.e. 4)
2) Get buff[N] bytes.
3) Walk the buffer, converting bytes to doubles (using
BitConverter.ToDouble(buff, indexer)) and putting into a List<double>.
4) Are they the same Endianess? If not, need to make that adjustment.

--
William Stacey [MVP]

"Macca" <Ma***@discussions.microsoft.com> wrote in message
news:97**********************************@microsof t.com...
| Hi William,
|
| Thanks for the reply. The server side is .NET but the client side is
| embedded C.
|
| I will know in advance how much data is being sent.
|
| e.g 10 packets of 256KB which will be sent and then needs to be
recompiled
| into and array of doubles.
|
| Can BinarySerializer still be used in this scenario. Is this a .NET
method?
|
| Thanks In Advance
| Macca
|
|
|
| "William Stacey [MVP]" wrote:
|
| > First, you need to know how many bytes you expect to receive or have
some
| > delimiter to tell you. If both sides are .Net, then the easiest way is
to
| > use BinarySerializer to/from byte[]. It does not matter how many
packets
| > are sent as long as you wait till you receive all bytes before the
| > conversion.
| >
| > --
| > William Stacey [MVP]
| >
| > "Macca" <Ma***@discussions.microsoft.com> wrote in message
| > news:AF**********************************@microsof t.com...
| > | Hi,
| > |
| > | My application receives data from multiple sources transferred over
| > | ethernet. This data is broken into packets of bytes before being
| > transmitted
| > | over the network.
| > |
| > | My application has to take the data and arrange into a user defined
| > | type/class.
| > |
| > | e.g one message from source 1 may be 10-15KB. This is broken down into
| > | smaller packets say for arguments sake 1KB.
| > |
| > | My application then has to take each packet and construct the data
back
| > into
| > | it's orginal size of 15KB.
| > |
| > | This will probably be stored in some sort of array/arraylist of
doubles
| > | rather than bytes.
| > |
| > | My question is :- what is the best/most efficient way of converting
the
| > | individual packets of bytes into an array of say doubles?
| > |
| > | Regards
| > | Macca
| > |
| >
| >
| >
Feb 11 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by steve | last post: by
6 posts views Thread by Mimi | last post: by
9 posts views Thread by Charles Law | last post: by
10 posts views Thread by Nikolay Petrov | last post: by
17 posts views Thread by =?Utf-8?B?U2hhcm9u?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.