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); }