THRIFT-5591 Add uuid type to IDL and implement reference code (+ improved self-tests)
Client: compiler general, netstd, Delphi
Patch: Jens Geyer
diff --git a/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs b/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs
index eee137c..ba2a7ab 100644
--- a/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs
+++ b/lib/netstd/Thrift/Protocol/TBinaryProtocol.cs
@@ -21,6 +21,7 @@
using System.Threading;
using System.Threading.Tasks;
using Thrift.Protocol.Entities;
+using Thrift.Protocol.Utilities;
using Thrift.Transport;
@@ -209,6 +210,14 @@
await Trans.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
}
+ public override async Task WriteUuidAsync(Guid uuid, CancellationToken cancellationToken)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+
+ var bytes = uuid.SwapByteOrder().ToByteArray();
+ await Trans.WriteAsync(bytes, 0, bytes.Length, cancellationToken);
+ }
+
public override async ValueTask<TMessage> ReadMessageBeginAsync(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -401,6 +410,16 @@
return buf;
}
+ public override async ValueTask<Guid> ReadUuidAsync(CancellationToken cancellationToken)
+ {
+ cancellationToken.ThrowIfCancellationRequested();
+
+ Transport.CheckReadBytesAvailable(16); // = sizeof(uuid)
+ var buf = new byte[16];
+ await Trans.ReadAllAsync(buf, 0, 16, cancellationToken);
+ return new Guid(buf).SwapByteOrder();
+ }
+
public override async ValueTask<string> ReadStringAsync(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
@@ -443,6 +462,7 @@
case TType.Map: return sizeof(int); // element count
case TType.Set: return sizeof(int); // element count
case TType.List: return sizeof(int); // element count
+ case TType.Uuid: return 16; // uuid bytes
default: throw new TProtocolException(TProtocolException.NOT_IMPLEMENTED, "unrecognized type code");
}
}