public override bool Decode(PacketData data) { var result = data.Data[data.Position] != 0; data.ShiftPosition(1); return(result); }
public override void Encode(ulong obj, PacketData data) { Int64Converter conv = obj; var pos = data.Position; var bytes = data.Data; if (BitConverter.IsLittleEndian) { bytes[pos] = conv.Byte0; bytes[pos + 1] = conv.Byte1; bytes[pos + 2] = conv.Byte2; bytes[pos + 3] = conv.Byte3; bytes[pos + 4] = conv.Byte4; bytes[pos + 5] = conv.Byte5; bytes[pos + 6] = conv.Byte6; bytes[pos + 7] = conv.Byte7; } else { bytes[pos + 7] = conv.Byte0; bytes[pos + 6] = conv.Byte1; bytes[pos + 5] = conv.Byte2; bytes[pos + 4] = conv.Byte3; bytes[pos + 3] = conv.Byte4; bytes[pos + 2] = conv.Byte5; bytes[pos + 1] = conv.Byte6; bytes[pos] = conv.Byte7; } data.ShiftPosition(ByteSize); }
public static void EncodeBoolArray <T>(T[] objs, PacketData data, Process process) { var arrayLength = objs.Length; var bytesLength = getBytesLength(arrayLength); //rounds up int pos = data.Position; data.ShiftPosition(bytesLength); int i = 0; for (int index = pos; index < pos + bytesLength; index++) { byte current = 0; for (int j = 0; j < 8 & i < arrayLength; j++) { if (!EqualityComparer <T> .Default.Equals(objs[i], default(T))) { current++; process(i); } current <<= 1; i++; } data.Data[index] = current; } }
public override sbyte Decode(PacketData data) { var result = (sbyte)data.Data[data.Position]; data.ShiftPosition(1); return(result); }
public override void Encode(string obj, PacketData data) { //int32 encoder is yet to shift pos var encodedLength = Encoding.GetBytes(obj, 0, obj.Length, data.Data, data.Position + 4); Types.Int32.Encode(encodedLength, data); data.ShiftPosition(encodedLength); }
public override string Decode(PacketData data) { var encodedLength = Types.Int32.Decode(data); //pos already shifted var pos = data.Position; data.ShiftPosition(encodedLength); return(Encoding.GetString(data.Data, pos, encodedLength)); }
public override int Decode(PacketData data) { var pos = data.Position; var bytes = data.Data; data.ShiftPosition(ByteSize); return(BitConverter.IsLittleEndian ? new Int32Converter(bytes[pos], bytes[pos + 1], bytes[pos + 2], bytes[pos + 3]) : new Int32Converter(bytes[pos + 3], bytes[pos + 2], bytes[pos + 1], bytes[pos])); }
public override void Encode(Guid obj, PacketData data) { var bytes = obj.ToByteArray(); if (BitConverter.IsLittleEndian) { FlipEndianness(bytes); } System.Array.Copy(bytes, 0, data.Data, data.Position, ByteSize); data.ShiftPosition(ByteSize); }
public override Guid Decode(PacketData data) { var bytes = new byte[ByteSize]; System.Array.Copy(data.Data, data.Position, bytes, 0, ByteSize); if (BitConverter.IsLittleEndian) { FlipEndianness(bytes); } data.ShiftPosition(ByteSize); return(new Guid(bytes)); }
public override void Encode(ushort obj, PacketData data) { Int16Converter conv = obj; var pos = data.Position; var bytes = data.Data; if (BitConverter.IsLittleEndian) { bytes[pos] = conv.Byte0; bytes[pos + 1] = conv.Byte1; } else { bytes[pos + 1] = conv.Byte0; bytes[pos] = conv.Byte1; } data.ShiftPosition(ByteSize); }
public static void DecodeBoolArray(PacketData data, int arrayLength, Process setValue) { var bytesLength = getBytesLength(arrayLength); //rounds up int pos = data.Position; data.ShiftPosition(bytesLength); int i = 0; for (int index = pos; index < pos + bytesLength; index++) { byte current = data.Data[index]; for (int j = 0; j < 8 & i < arrayLength; j++) { if ((current & 1) == 1) { setValue(i); } current <<= 1; i++; } } }
public override void Encode(bool obj, PacketData data) { data.Data[data.Position] = obj ? (byte)1 : (byte)0; data.ShiftPosition(1); }
public override void Encode(sbyte obj, PacketData data) { data.Data[data.Position] = (byte)obj; data.ShiftPosition(1); }