internal static YMSGPacket FromBytes(byte[] data) { YMSGPacket retVal = new YMSGPacket(); retVal.Version = (short)(data[4] << 8 | (data[5])); retVal.Size = (short)(data[8] << 8 | data[9]); retVal.Service = (short)(data[10] << 8 | data[11]); retVal.Status = (int)(data[12] << 24 | data[13] << 16 | data[14] << 8 | data[15]); retVal.SessionID = (int)(data[16] << 24 | data[17] << 16 | data[18] << 8 | data[19]); byte[] payload = new byte[retVal.Size]; Buffer.BlockCopy(data, 20, payload, 0, payload.Length); int i = 0; while (payload.FindIndex(PayloadDelimeter, i) > -1) { int length = payload.FindIndex(PayloadDelimeter, i); string s1 = GetEncoding().GetString(payload.Slice(length, i)); i += length + 2; length = payload.FindIndex(PayloadDelimeter, i); string s2 = GetEncoding().GetString(payload.Slice(length, i)); i += length + 2; retVal._Payload.Add(new PayloadEntry(s1, s2)); } return(retVal); }
public byte[] ToBytes() { List <byte> retVal = new List <byte>(); foreach (PayloadEntry kv in this) { byte[] k = YMSGPacket.GetEncoding().GetBytes(kv.Key); byte[] j = YMSGPacket.GetEncoding().GetBytes(kv.Value); retVal.AddRange(k); retVal.AddRange(PayloadDelimeter); retVal.AddRange(j); retVal.AddRange(PayloadDelimeter); } return(retVal.ToArray()); }
internal static YMSGPacket FromBytes(byte[] data) { YMSGPacket retVal = new YMSGPacket(); retVal.Version = (short)(data[4] << 8 | (data[5])); retVal.Size = (short)(data[8] << 8 | data[9]); retVal.Service = (short)(data[10] << 8 | data[11]); retVal.Status = (int)(data[12] << 24 | data[13] << 16 | data[14] << 8 | data[15]); retVal.SessionID = (int)(data[16] << 24 | data[17] << 16 | data[18] << 8 | data[19]); byte[] payload = new byte[retVal.Size]; Buffer.BlockCopy(data, 20, payload, 0, payload.Length); int i = 0; while(payload.FindIndex(PayloadDelimeter, i) > -1) { int length = payload.FindIndex(PayloadDelimeter, i); string s1 = GetEncoding().GetString(payload.Slice(length, i)); i += length + 2; length = payload.FindIndex(PayloadDelimeter, i); string s2 = GetEncoding().GetString(payload.Slice(length, i)); i += length + 2; retVal._Payload.Add(new PayloadEntry(s1, s2)); } return retVal; }
public YMSGMessageEventArgs(YMSGPacket packet, DateTime timeStamp) { this.YMSGData = packet; this.TimeStamp = timeStamp; }
public YMSGUser(YMSGPacket.Payload payload, YMSGUserType type) { _payload = payload; Type = type; //TODO: build object }