public override object Read(IProtocolBuffer buffer) { string value = buffer.ReadBCD(6); int year = int.Parse("20" + value.Substring(0, 2)); int month = int.Parse(value.Substring(2, 2)); int day = int.Parse(value.Substring(4, 2)); int hh = int.Parse(value.Substring(6, 2)); int mm = int.Parse(value.Substring(8, 2)); int ss = int.Parse(value.Substring(10, 2)); return(new DateTime(year, month, day, hh, mm, ss)); }
public void Read(IProtocolBuffer buffer) { //byte crc = Core.GetCRC(buffer.Array, 1, buffer.Length - 3); //CRC = buffer.Array[buffer.Length - 2]; //if(CRC != crc) // throw new ProtocolProcessError("message check CRC error!"); buffer.Read(); //read start 标识位 ID = buffer.ReadUInt16(); //read id 消息 ID Property.Read(buffer); //read property 消息体属性 SIM = buffer.ReadBCD(6); //read sim 终端手机号 No = buffer.ReadUInt16(); //read no 消息流水号 if (Property.IsPacket) //read packet 消息包封装项 { Packet = new PacketInfo(); Packet.Load(buffer); } if (Property.BodyLength > 0) //read body 消息体 { IProtocolBuffer bodybuffer = ProtocolBufferPool.Default.Pop(); try { buffer.ReadSubBuffer(bodybuffer, Property.BodyLength); Serializer serializer = SerializerFactory.Defalut.Get(ID); if (serializer != null) { Body = serializer.CreateObject(); serializer.Deserialize(Body, bodybuffer); } } finally { ProtocolBufferPool.Default.Push(bodybuffer); } } CRC = buffer.Read(); //read crc 检验码 buffer.Read(); //read end 标识位 }
public void Load(IProtocolBuffer buffer) { byte crc = Core.GetCRC(buffer.Array, 1, buffer.Length - 3); this.CRC = buffer.Array[buffer.Length - 2]; if (this.CRC != crc) { throw new ProtocolProcessError("message check CRC error!"); } buffer.Read(); //read start ID = buffer.ReadUInt16(); //read id Property.Load(buffer); //read property SIM = buffer.ReadBCD(6); //read sim BussinessNO = buffer.ReadUInt16(); //read no if (Property.IsPacket) //read packet { Packet = new PacketInfo(); Packet.Load(buffer); } if (Property.BodyLength > 0) //read body { IProtocolBuffer bodybuffer = ProtocolBufferPool.Default.Pop(); try { buffer.ReadSubBuffer(bodybuffer, Property.BodyLength); Serializer serializer = SerializerFactory.Defalut.Get(ID); Body = serializer.CreateObject(); serializer.Deserialize(Body, bodybuffer); } finally { ProtocolBufferPool.Default.Push(bodybuffer); } } this.CRC = buffer.Read(); //read crc buffer.Read(); //read end }
public override object Read(IProtocolBuffer buffer) { return(buffer.ReadBCD(Length)); }