Esempio n. 1
0
        public static MatchingEngineResult Deserialize(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("Invalid Message");
            }

            var version = BitConverter.ToInt16(bytes, versionOffset);

            if (version != MatchingEngineResultSerializer.version)
            {
                throw new Exception("version mismatch");
            }

            var result = new MatchingEngineResult();

            result.OrderId   = BitConverter.ToUInt64(bytes, orderIdOffset);
            result.Result    = (OrderMatchingResult)bytes[resultOffset];
            result.Timestamp = BitConverter.ToInt64(bytes, timestampOffset);
            return(result);
        }
Esempio n. 2
0
 public static byte[] Serialize(MatchingEngineResult matchingEngineResult)
 {
     if (matchingEngineResult == null)
     {
         throw new ArgumentNullException(nameof(matchingEngineResult));
     }
     return(Serialize(matchingEngineResult.OrderId, matchingEngineResult.Result, matchingEngineResult.Timestamp));
 }