public void Pack(ICustomDataOutput header) { var data = new CustomDataWriter(); Serialize(data); var size = data.Data.Length; var compute = ComputeTypeLen(size); short val = (short)((MessageId << 2) | compute); header.WriteShort(val); switch (compute) { case 1: header.WriteByte((byte)size); break; case 2: header.WriteUShort((ushort)size); break; case 3: header.WriteByte((byte)((size >> 0x10) & 0xff)); header.WriteUShort((ushort)(size & 0xffff)); break; } header.WriteBytes(data.Data); data.Dispose(); }
public void Pack(ICustomDataOutput header) { var data = new CustomDataWriter(); Serialize(data); var size = data.Data.Length; var compute = ComputeTypeLen(size); short val = (short)((MessageId << 2) | compute); header.WriteShort(val); switch (compute) { case 1: header.WriteByte((byte)size); //header.WriteByte(0);//... break; case 2: header.WriteUShort((ushort)size); break; case 3: header.WriteByte((byte)((size >> 0x10) & 0xff)); header.WriteUShort((ushort)(size & 0xffff)); break; } header.WriteBytes(data.Data); data.Dispose(); /*byte b = 3; * short @short = (short)Message.SubComputeStaticHeader(this.MessageId, 3); * writer.WriteShort(@short); * for (int i = 3 - 1; i >= 0; i--) * { * writer.WriteByte(0); * } * this.Serialize(writer); * long num = writer.Position - 5L; * writer.Seek(2); * for (int i = (int)(b - 1); i >= 0; i--) * { * writer.WriteByte((byte)(num >> 8 * i & 255L)); * } * writer.Seek((int)num + 5);*/ }