public static CancelRequest Deserialize(byte[] bytes) { if (bytes == null) { throw new ArgumentNullException(nameof(bytes)); } if (bytes.Length != sizeOfMessage) { throw new Exception("Cancel Request Message must be of Size : " + sizeOfMessage); } var messageType = (MessageType)(bytes[messageTypeOffset]); if (messageType != MessageType.CancelRequest) { throw new Exception("Invalid Message"); } var version = BitConverter.ToInt16(bytes, versionOffset); if (version != CancelRequestSerializer.version) { throw new Exception("version mismatch"); } var cancelRequest = new CancelRequest(); cancelRequest.OrderId = BitConverter.ToInt32(bytes, orderIdOffset); return(cancelRequest); }
public static byte[] Serialize(CancelRequest cancelRequest) { if (cancelRequest == null) { throw new ArgumentNullException(nameof(cancelRequest)); } byte[] msg = new byte[sizeOfMessage]; Write(msg, messageLengthOffset, sizeOfMessage); msg[messageTypeOffset] = (byte)MessageType.CancelRequest; Write(msg, versionOffset, version); Write(msg, orderIdOffset, cancelRequest.OrderId); return(msg); }