public BaseMessage(byte[] payload, MessageType messageType, ushort sourceId, ushort destinationId, ushort realSourceId, ushort realDestinationId, Guid id = new Guid(), MessageFlags messageFlags = MessageFlags.None) { Payload = payload; MessageType = messageType; Guid = id; SourceId = sourceId; DestinationId = destinationId; RealDestinationId = realDestinationId; RealSourceId = realSourceId; MessageFlags |= messageFlags; RealHash = HashUtil.ComputeChecksum(Payload); }
public BaseMessage(byte[] messageData) { var reader = new BigEndianBinaryReader(new MemoryStream(messageData)); var messageInfo = reader.ReadByte(); MessageFlags = (MessageFlags)(messageInfo >> 5); MessageType = (MessageType)(messageInfo & 0x1F); if (MessageFlags.HasFlag(MessageFlags.IsRedirected)) { RealSourceId = reader.ReadUInt16(); } SourceId = reader.ReadUInt16(); DestinationId = reader.ReadUInt16(); if (MessageType.IsReliable()) { Guid = new Guid(reader.ReadBytes(16)); Hash = reader.ReadBytes(HashUtil.GetHashSize()); } var payloadLength = reader.ReadInt32(); if (payloadLength < 0) { throw new DnmpException($"Payload length < 0: {payloadLength}"); } if (payloadLength > 128 * 1024 * 1024) { throw new DnmpException("tLen is larger than 20MiB"); } Payload = reader.ReadBytes(payloadLength); RealHash = HashUtil.ComputeChecksum(Payload); }