public async Task<ApduResponse> QueryApduAsync(ApduRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var requestBytes = ApduCodec.EncodeRequest(request); var responseBytes = await QueryAsync(requestBytes, cancellationToken); return ApduCodec.DecodeResponse(responseBytes); }
public static ArraySegment<byte> EncodeRequest(ApduRequest request) { if (request.Data.Count > maxDataSize) { throw new ArgumentOutOfRangeException(nameof(request), "The data length is too big"); } var buffer = new byte[7 + request.Data.Count]; using (var stream = new MemoryStream(buffer)) { stream.WriteByte(0); stream.WriteByte(request.CommandCode); stream.WriteByte(request.Parameter1); stream.WriteByte(request.Parameter2); Write3ByteIntBigEndian(stream, (uint)request.Data.Count); stream.Write(request.Data.Array, request.Data.Offset, request.Data.Count); } return buffer.Segment(); }
public static ArraySegment <byte> EncodeRequest(ApduRequest request) { if (request.Data.Count > maxDataSize) { throw new ArgumentOutOfRangeException(nameof(request), "The data length is too big"); } var buffer = new byte[7 + request.Data.Count]; using (var stream = new MemoryStream(buffer)) { stream.WriteByte(0); stream.WriteByte(request.CommandCode); stream.WriteByte(request.Parameter1); stream.WriteByte(request.Parameter2); Write3ByteIntBigEndian(stream, (uint)request.Data.Count); stream.Write(request.Data.Array, request.Data.Offset, request.Data.Count); } return(buffer.Segment()); }