public static byte[] Serialize(CancelledOrder cancelledOrder) { if (cancelledOrder == null) { throw new ArgumentNullException(nameof(cancelledOrder)); } return(Serialize(cancelledOrder.OrderId, cancelledOrder.RemainingQuantity, cancelledOrder.Cost, cancelledOrder.Fee, cancelledOrder.CancelReason, cancelledOrder.Timestamp)); }
public static CancelledOrder Deserialize(byte[] bytes) { if (bytes == null) { throw new ArgumentNullException(nameof(bytes)); } if (bytes.Length != sizeOfMessage) { throw new Exception("Canceled Order Message must be of Size : " + sizeOfMessage); } var messageType = (MessageType)(bytes[messageTypeOffset]); if (messageType != MessageType.Cancel) { throw new Exception("Invalid Message"); } var version = BitConverter.ToInt16(bytes, versionOffset); if (version != CancelledOrderSerializer.version) { throw new Exception("version mismatch"); } var cancelledOrder = new CancelledOrder(); cancelledOrder.OrderId = BitConverter.ToInt32(bytes, orderIdOffset); cancelledOrder.RemainingQuantity = ReadQuantity(bytes, remainingQuantityOffset); cancelledOrder.CancelReason = (CancelReason)bytes[cancelReasonOffset]; cancelledOrder.Timestamp = BitConverter.ToInt32(bytes, timestampOffset); cancelledOrder.Cost = ReadQuantity(bytes, costOffset); cancelledOrder.Fee = ReadQuantity(bytes, feeOffset); return(cancelledOrder); }