// __ Serialization ___________________________________________________


        public static MavLinkPacket GetPacketForMessage(
            UasMessage msg, byte systemId, byte componentId, byte sequenceNumber)
        {
            MavLinkPacket result = new MavLinkPacket()
            {
                SystemId             = systemId,
                ComponentId          = componentId,
                PacketSequenceNumber = sequenceNumber,
                MessageId            = msg.MessageId,
                Message = msg
            };

            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    msg.SerializeBody(bw);
                }

                result.Payload       = ms.ToArray();
                result.PayLoadLength = (byte)result.Payload.Length;
                result.UpdateCrc();
            }

            return(result);
        }
        public static byte[] GetBytesForMessage(
            UasMessage msg, byte systemId, byte componentId, byte sequenceNumber, byte signalMark)
        {
            MavLinkPacket p = MavLinkPacket.GetPacketForMessage(
                msg, systemId, componentId, sequenceNumber);

            int bufferSize = p.GetPacketSize();

            if (signalMark != 0)
            {
                bufferSize++;
            }

            byte[] result = new byte[bufferSize];

            using (MemoryStream s = new MemoryStream(result))
            {
                using (BinaryWriter w = new BinaryWriter(s))
                {
                    if (signalMark != 0)
                    {
                        w.Write(signalMark);
                    }
                    p.Serialize(w);
                }
            }

            return(result);
        }
        private void DeserializeMessage()
        {
            UasMessage result = UasSummary.CreateFromId(MessageId);

            if (result == null)
            {
                return;                  // Unknown type
            }
            using (MemoryStream ms = new MemoryStream(Payload))
            {
                using (BinaryReader br = GetBinaryReader(ms))
                {
                    result.DeserializeBody(br);
                }
            }

            Message = result;
            IsValid = true;
        }