public static MatchingEngineResult Deserialize(ReadOnlySpan <byte> bytes) { if (bytes == null) { throw new ArgumentNullException(nameof(bytes)); } if (bytes.Length != sizeOfMessage) { throw new Exception("OrderMatchingResult Message must be of Size : " + sizeOfMessage); } var messageType = (MessageType)(bytes[messageTypeOffset]); if (messageType != MessageType.OrderMatchingResult) { throw new Exception(Constant.INVALID_MESSAGE); } var version = BitConverter.ToInt16(bytes.Slice(versionOffset)); if (version != MatchingEngineResultSerializer.version) { throw new Exception(Constant.INVALID_VERSION); } var result = new MatchingEngineResult(); result.OrderId = BitConverter.ToUInt64(bytes.Slice(orderIdOffset)); result.Result = (OrderMatchingResult)bytes[resultOffset]; result.Timestamp = BitConverter.ToInt64(bytes.Slice(timestampOffset)); return(result); }
public static void Serialize(MatchingEngineResult matchingEngineResult, Span <byte> bytes) { if (matchingEngineResult == null) { throw new ArgumentNullException(nameof(matchingEngineResult)); } if (bytes == null) { throw new ArgumentNullException(nameof(bytes)); } Serialize(matchingEngineResult.OrderId, matchingEngineResult.Result, matchingEngineResult.Timestamp, bytes); }