Exemplo n.º 1
0
        public Message(byte[] buffer, int offset)
            : base(buffer, offset)
        {
            Contract.Requires<ArgumentNullException>(buffer != null, "buffer");
            Contract.Requires<ArgumentException>(buffer.Length >= Message.MinimumByteSize, "buffer");
            Contract.Requires<ArgumentOutOfRangeException>(offset >= 0, "offset");
            Contract.Requires<ArgumentOutOfRangeException>(offset <= buffer.Length - Message.MinimumByteSize, "offset");

            Network = (MessageNetwork)buffer.ReadUInt32(offset);
            Command = Encoding.ASCII.GetString(buffer, Command_Offset(ref offset), MAX_COMMAND_LENGTH).TrimEnd('\0');
            PayloadLength = buffer.ReadUInt32(PayloadLength_Offset(ref offset));

            ByteSize = ((uint)Network).ByteSize() + MAX_COMMAND_LENGTH * BufferOperations.UINT8_SIZE + PayloadLength.ByteSize();

            if (MessagePayloadFactory.PayloadRequiresChecksum(Command))
            {
                Checksum = buffer.ReadUInt32(Checksum_Offset(ref offset));

                ByteSize += Checksum.ByteSize();
            }

            Payload = MessagePayloadFactory.ConstructMessagePayload(Command, buffer, Payload_Offset(ref offset), PayloadLength);

            ByteSize += Payload.ByteSize;
        }
Exemplo n.º 2
0
        public Message(byte[] buffer, int offset)
            : base(buffer, offset)
        {
            Contract.Requires <ArgumentNullException>(buffer != null, "buffer");
            Contract.Requires <ArgumentException>(buffer.Length >= Message.MinimumByteSize, "buffer");
            Contract.Requires <ArgumentOutOfRangeException>(offset >= 0, "offset");
            Contract.Requires <ArgumentOutOfRangeException>(offset <= buffer.Length - Message.MinimumByteSize, "offset");

            Network       = (MessageNetwork)buffer.ReadUInt32(offset);
            Command       = Encoding.ASCII.GetString(buffer, Command_Offset(ref offset), MAX_COMMAND_LENGTH).TrimEnd('\0');
            PayloadLength = buffer.ReadUInt32(PayloadLength_Offset(ref offset));

            ByteSize = ((uint)Network).ByteSize() + MAX_COMMAND_LENGTH * BufferOperations.UINT8_SIZE + PayloadLength.ByteSize();

            if (MessagePayloadFactory.PayloadRequiresChecksum(Command))
            {
                Checksum = buffer.ReadUInt32(Checksum_Offset(ref offset));

                ByteSize += Checksum.ByteSize();
            }

            Payload = MessagePayloadFactory.ConstructMessagePayload(Command, buffer, Payload_Offset(ref offset), PayloadLength);

            ByteSize += Payload.ByteSize;
        }