Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Char array to a class

Tags:

c++

.net

managed

I have a incoming stream of bytes (unsigned char) from either a file or network. I need this data placed in a class, and is looking for a NET-way of doing this.

I bet some does this all the time, so I guess there is a better method to do this than using BitConverter.

I realize I supplied too litle information. Let me try with an example class:

class data { 
void doSmething(); 
int var1; 
float var2; 
} 

Then I want to transfer the data (var1 and var2) contained in this class over f.ex. a network socket and receive the data on the other end

like image 535
rozon Avatar asked Dec 18 '25 17:12

rozon


2 Answers

As Jon mentioned, it's not clear, what you need. Maybe you are talking about maybe it is Binary serialization what you are looking for?

like image 176
PiRX Avatar answered Dec 20 '25 07:12

PiRX


It's not entirely clear what you mean, but if you're basically looking for a way to buffer the data so you can get at it later, MemoryStream is probably your best bet. Write all your data to it, then set Position to 0 and you can read the data back again.

like image 22
Jon Skeet Avatar answered Dec 20 '25 05:12

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!