public void Write(IProtocolBuffer buffer) { IProtocolBuffer bodybuffer = null; try { if (Packet != null) { Property.IsPacket = true; } if (Body != null) { Serializer serializer = SerializerFactory.Defalut.Get(Body.GetType()); if (serializer == null) { throw new ProtocolProcessError(string.Format("{0} serializer not found!", Body)); } ID = serializer.MessageType.ID; if (!serializer.MessageType.NoBody) { bodybuffer = ProtocolBufferPool.Default.Pop(); serializer.Serialize(Body, bodybuffer); if (bodybuffer.Length > MessageBodyProperty.BODY_LENGTH) { throw new ProtocolProcessError("message body to long!"); } Property.BodyLength = (ushort)bodybuffer.Length; } } buffer.WriteTag(); //write start buffer.Write(ID); //write id Property.Write(buffer); //write body property buffer.WriteBCD(SIM); //write sim buffer.Write(No); //write no if (Packet != null) //write packet { Packet.Save(buffer); } if (bodybuffer != null) //write body { buffer.WriteSubBuffer(bodybuffer); } byte crc = BufferUtils.GetCRC(buffer.Array, 1, buffer.Length - 1); buffer.Write(crc); //write crc buffer.WriteTag(); //write end } finally { if (bodybuffer != null) { ProtocolBufferPool.Default.Push(bodybuffer); } } }
public void Save(IProtocolBuffer buffer) { ushort value = (ushort)(BodyLength & BODY_LENGTH); if (CustomHigh) { value |= CUSTOM_HEIGHT; } if (CustomLow) { value |= CUSTOM_LOW; } if (IsPacket) { value |= IS_PACKET; } if (EncryptHigh) { value |= ENCRYPT_HEIGHT; } if (EncryptMiddle) { value |= ENCRYPT_MIDDLE; } if (EncryptLow) { value |= ENCRYPT_LOW; } buffer.Write(value); }
public override void Write(object value, IProtocolBuffer buffer) { buffer.Write((uint)value); }
public override void Write(object value, IProtocolBuffer buffer) { uint data = (uint)((IBitCustomType)value).Save(); buffer.Write(data); }