473,225 Members | 1,414 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,225 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 5533
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: steve | last post by:
I need to get byte values from an object into a byte in order to write the bytes to file. An object (vSound) is passed to a function. From the Autos window I can see that the Value of vSound is...
6
by: Mimi | last post by:
Is there a way to convert int to byte easily? I want to write my int indexTbl to a MemoryStream but the MemoryStream class only accepts byte buffer. I have more than one int indexTbl to write...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
9
by: Charles Law | last post by:
Suppose I have a structure Private Structure MyStruct Dim el1 As Byte Dim el2 As Int16 Dim el3 As Byte End Structure I want to convert this into a byte array where
10
by: Nikolay Petrov | last post by:
How can I convert DOS cyrillic text to Unicode
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
2
by: shahiz | last post by:
basically im having null pointer exception //read an inputstream is = new DataInputStream(new FileInputStream("test.mpg")); loadBytes(is); //pass it as a datasource for the player public...
19
by: est | last post by:
From python manual str( ) Return a string containing a nicely printable representation of an object. For strings, this returns the string itself. The difference with repr(object) is that...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.