public override bool Serialize(ref PacketOutStream Data, bool Force) { if (!Force && (val == null || val.ToString() == "0")) { return(false); } if (val is byte[]) { Data.Write((byte[])val); } else if (val is long) { Data.WriteInt64R((long)val); } else if (val is UInt64) { Data.WriteUInt64R((UInt64)val); } else { return(false); } return(true); }
public override bool Serialize(ref PacketOutStream Data, bool Force) { if (!Force && (val == null || val.ToString() == "0")) { return(false); } byte[] Result = new byte[0]; if (val is string) { Result = UTF8Encoding.UTF8.GetBytes((val as string)); } else if (val is byte[]) { Result = (val as byte[]); } if (Result == null || Result.Length <= 0) { return(false); } Data.WriteEncoded7Bit(Result.Length); Data.Write(Result); return(true); }
public override bool Serialize(ref PacketOutStream Data, bool Force) { if (!Force && (val == null || val.ToString() == "0")) { return(false); } if (val is UInt32) { Data.WriteUInt32R((UInt32)val); } else if (val is Int32) { Data.WriteInt32R((Int32)val); } else if (val is float) { Data.WriteFloat((float)val); } else if (val is byte[]) { Data.Write((byte[])val); } else { return(false); } return(true); }
public void SendTCPWithSize(byte[] ToSend) { PacketOutStream St = new PacketOutStream(); St.WriteEncoded7Bit(ToSend.Length); St.Write(ToSend); SendTCP(St.ToArray()); }
public static bool WriteField(ref PacketOutStream Stream, ISerializableField Field, int FieldIndex, int FieldType) { if (FieldType == (int)EPacketFieldType.Invalid) { return(false); } PacketOutStream NewStream = new PacketOutStream(); long FieldResult; PacketOutStream.Encode2Parameters(out FieldResult, FieldType, FieldIndex); NewStream.WriteEncoded7Bit(FieldResult); if (Field == null || Field.Serialize(ref NewStream, false)) { Stream.Write(NewStream.ToArray()); } return(true); }
public static bool WritePacket(ref PacketOutStream Stream, ISerializablePacket Packet, bool WithSize = true, bool WithTerminator = true, bool WithOpcode = true) { if (Packet == null) { return(false); } lock (Packet) { Packet.ConvertToField(); PacketOutStream Data = new PacketOutStream(); if (WithOpcode) { Data.WriteEncoded7Bit(Packet.Opcode); } foreach (ISerializableField Field in Packet.GetFields().Values) { WriteField(ref Data, Field); } if (WithTerminator && Packet.Opcode != (int)Opcodes.ProtocolHandshakeCompression) { WriteField(ref Data, null, 0, (int)EPacketFieldType.Terminator); } if (WithSize) { Stream.WriteEncoded7Bit(Data.Length); } Stream.Write(Data.ToArray()); Packet.Fields.Clear(); } return(true); }