added client id to protocol
This commit is contained in:
@@ -28,7 +28,7 @@ namespace Client
|
||||
|
||||
public static bool getJsonIdentifier(byte[] bytes, out string identifier)
|
||||
{
|
||||
if (bytes.Length <= 5)
|
||||
if (bytes.Length <= 6)
|
||||
{
|
||||
throw new ArgumentException("bytes to short");
|
||||
}
|
||||
@@ -36,7 +36,7 @@ namespace Client
|
||||
|
||||
if (messageId == 1)
|
||||
{
|
||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(5).ToArray()));
|
||||
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(6).ToArray()));
|
||||
identifier = json.identifier;
|
||||
return true;
|
||||
}
|
||||
@@ -49,37 +49,37 @@ namespace Client
|
||||
|
||||
public static bool isRawData(byte[] bytes)
|
||||
{
|
||||
if (bytes.Length <= 5)
|
||||
if (bytes.Length <= 6)
|
||||
{
|
||||
throw new ArgumentException("bytes to short");
|
||||
}
|
||||
return bytes[5] == 0x02;
|
||||
}
|
||||
|
||||
private static byte[] getMessage(byte[] payload, byte messageId)
|
||||
private static byte[] getMessage(byte[] payload, byte messageId, byte clientId)
|
||||
{
|
||||
byte[] res = new byte[payload.Length + 5];
|
||||
byte[] res = new byte[payload.Length + 6];
|
||||
|
||||
Array.Copy(BitConverter.GetBytes(payload.Length + 5), 0, res, 0, 4);
|
||||
Array.Copy(BitConverter.GetBytes(payload.Length + 6), 0, res, 0, 4);
|
||||
res[4] = messageId;
|
||||
Array.Copy(payload, 0, res, 5, payload.Length);
|
||||
Array.Copy(payload, 0, res, 6, payload.Length);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static byte[] GetRawDataMessage(byte[] payload)
|
||||
public static byte[] GetRawDataMessage(byte[] payload, byte clientId)
|
||||
{
|
||||
return getMessage(payload, 0x02);
|
||||
return getMessage(payload, 0x02, clientId);
|
||||
}
|
||||
|
||||
public static byte[] getJsonMessage(byte[] payload)
|
||||
public static byte[] getJsonMessage(byte[] payload, byte clientId)
|
||||
{
|
||||
return getMessage(payload, 0x01);
|
||||
return getMessage(payload, 0x01, clientId);
|
||||
}
|
||||
|
||||
public static byte[] getJsonMessage(string message)
|
||||
public static byte[] getJsonMessage(string message, byte clientId)
|
||||
{
|
||||
return getJsonMessage(Encoding.ASCII.GetBytes(message));
|
||||
return getJsonMessage(Encoding.ASCII.GetBytes(message), clientId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user