예제 #1
0
        private ProtocolPacket StringToPacket(string line)
        {
            TextDataReader    reader = new TextDataReader(line.Trim());
            ProtocolCommandId cmd    = (ProtocolCommandId)Enum.Parse(typeof(ProtocolCommandId), reader.ReadString());

            return(ProtocolPacket.FromData(cmd, reader));
        }
        public static ProtocolPacket ReadPacket(BinaryReader reader, int total_len)
        {
            int  chksum = reader.ReadInt32NetworkOrder();
            byte cmd    = reader.ReadByte();

            byte[] data = reader.ReadAllBytes(total_len - 1);
            if (CalculateChecksum(cmd, data) != chksum)
            {
                throw new InvalidDataException("Checksum does not match");
            }

            return(ProtocolPacket.FromData((ProtocolCommandId)cmd, new BinaryDataReader(data)));
        }