public int Serialize(byte[] buffer, int offset) { PacketV2Helper.SetStx(buffer, offset); PacketV2Helper.SetIncompatFlags(buffer, offset, IncompatFlags); PacketV2Helper.SetCompatFlags(buffer, offset, CompatFlags); PacketV2Helper.SetSequence(buffer, offset, Sequence); PacketV2Helper.SetSystemId(buffer, offset, SystemId); PacketV2Helper.SetComponenId(buffer, offset, ComponenId); PacketV2Helper.SetMessageId(buffer, offset, MessageId); var payloadSize = Payload.Serialize(buffer, offset + PacketV2Helper.PaylodStartIndexInFrame); PacketV2Helper.SetPayloadSize(buffer, offset, (byte)payloadSize); PacketV2Helper.SetCrc(buffer, offset, GetCrcEtra()); if (Signature.IsPresent) { Signature.Serialize(buffer, offset + payloadSize + PacketV2Helper.PacketV2FrameSize); } return(payloadSize + Signature.ByteSize + PacketV2Helper.PacketV2FrameSize); }
public int Serialize(byte[] buffer, int offset) { PacketV2Helper.SetStx(buffer, offset); PacketV2Helper.SetIncompatFlags(buffer, offset, IncompatFlags); PacketV2Helper.SetCompatFlags(buffer, offset, CompatFlags); PacketV2Helper.SetSequence(buffer, offset, Sequence); PacketV2Helper.SetSystemId(buffer, offset, SystemId); PacketV2Helper.SetComponenId(buffer, offset, ComponenId); PacketV2Helper.SetMessageId(buffer, offset, MessageId); var index = offset + PacketV2Helper.PaylodStartIndexInFrame; var payloadSize = Payload.Serialize(buffer, index); Debug.Assert(payloadSize <= byte.MaxValue, $"Wrong payload serialize size (must be {byte.MaxValue} size)"); PacketV2Helper.SetPayloadSize(buffer, offset, (byte)payloadSize); PacketV2Helper.SetCrc(buffer, offset, GetCrcEtra()); if (Signature.IsPresent) { Signature.Serialize(buffer, offset + payloadSize + PacketV2Helper.PacketV2FrameSize); } return(payloadSize + Signature.ByteSize + PacketV2Helper.PacketV2FrameSize); }
public int Deserialize(byte[] buffer, int offset) { PacketV2Helper.VerifyStx(buffer, offset); var payloadSize = PacketV2Helper.GetPayloadSize(buffer, offset); IncompatFlags = PacketV2Helper.GetIncompatFlags(buffer, offset); CompatFlags = PacketV2Helper.GetCompatFlags(buffer, offset); Sequence = PacketV2Helper.GetSequence(buffer, offset); SystemId = PacketV2Helper.GetSystemId(buffer, offset); ComponenId = PacketV2Helper.GetComponenId(buffer, offset); var messageId = PacketV2Helper.GetMessageId(buffer, offset); if (messageId != MessageId) { throw new MavlinkException(string.Format(RS.PacketV2_Deserialize_Error_message_id_type, MessageId, messageId)); } Payload.Deserialize(buffer, offset + PacketV2Helper.PaylodStartIndexInFrame, payloadSize); PacketV2Helper.VerifyCrc(buffer, offset, GetCrcEtra()); if (PacketV2Helper.CheckSignaturePresent(buffer, offset)) { Signature.Deserialize(buffer, PacketV2Helper.GetSignatureStartIndex(buffer, offset)); } return(payloadSize + Signature.ByteSize + PacketV2Helper.PacketV2FrameSize); }