By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,337 Members | 1,323 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,337 IT Pros & Developers. It's quick & easy.

struct to byte[] conversion

P: n/a
Hi all,
1. if I use BinaryFormatter(for the struct below) I get:

   IMsgProtocol, Version=1.0.1291.23445, Culture=neutral,
PublicKeyToken=null msgProtocol.Login uinhashstatus description
msgProtocol.eStatus  Y msgProtocol.eStatus
value__    asdasda
2. is the easier way to convert Header struct to byte[]
and back just like record in C
(somthing like BinaryFormatter but without this all
useless (for me) things)
public enum eStatus
NotAvail = 0x0001,
Avail = 0x0002,
Busy = 0x0003,
Invisible = 0x0014,

public struct Login
public Login(byte[] inbyte)
uin = BitConverter.ToInt32(inbyte,0);
hash = BitConverter.ToInt32(inbyte, 4);
status = (eStatus)BitConverter.ToInt32(inbyte, 2 * 4);
description = Encoding.ASCII.GetString(inbyte,3*4,inbyte.Length - 3 *
4);// BitConverter.ToString(inbyte, 3 * 4);
public int uin;
public int hash;
public eStatus status;
public string description;
public byte[] GetBytes()
byte[] ret;
MemoryStream ms = new MemoryStream();
ret = BitConverter.GetBytes(uin);
ret = BitConverter.GetBytes(hash);
ret = BitConverter.GetBytes((int)status);
ret = Encoding.ASCII.GetBytes(description);
return ms.ToArray();

Selvin - Przemek Sulikowski
Nov 13 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.