Created
October 1, 2015 01:27
-
-
Save KennethanCeyer/285e96c20af460296f70 to your computer and use it in GitHub Desktop.
About little endian and big endian when socket programing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private List<byte> bnetData = new List<byte>(); | |
private BnetHelper bnetHelper = BnetHelper.getInstance(); | |
public byte bnetCommand; | |
public int serverToken = 0; | |
public int clientToken = 0; | |
public BnetProtocol() | |
{ | |
} | |
public void setBnetByte(byte[] byteData) | |
{ | |
foreach (byte data in byteData) | |
{ | |
bnetData.Add(data); | |
} | |
} | |
public void setBnetByte(UInt32 intData, bool isVariable = false) | |
{ | |
byte[] bData = BitConverter.GetBytes(intData); | |
// In transport, you have to use the big endian. | |
if (BitConverter.IsLittleEndian) | |
Array.Reverse(bData); | |
foreach (byte data in bData) | |
{ | |
bnetData.Add(data); | |
} | |
} | |
public void setBnetByte(String strData, bool isVariable = false) | |
{ | |
String hexData = bnetHelper.Acsii2Hex(strData); | |
if (isVariable) | |
{ | |
byte[] bData = bnetHelper.Hex2Byte(hexData); | |
this.setBnetByte(bData); | |
} | |
else { | |
UInt32 intData = UInt32.Parse(hexData, System.Globalization.NumberStyles.AllowHexSpecifier); | |
this.setBnetByte(intData, isVariable); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BnetHelper class는 무엇인가요?