TProtocol protocol = new TBinaryProtocol(new TMemoryBuffer()); var field = await protocol.ReadFieldBeginAsync(); // Check if the field is a stop field if (field.Type == TType.Stop) { // Do something }
using Thrift.Transport; using Thrift.Protocol; public async TaskThis example shows a method that deserializes a TProtocol message into an object. The method reads the fields in the message by calling the ReadFieldBeginAsync method and deserializes the values using the DeserializeValueAsync method. It then sets the deserialized values to the corresponding fields in the object. This example uses the Thrift package library.DeserializeAsync (byte[] message) { var transport = new TMemoryBuffer(message); var protocol = new TBinaryProtocol(transport); var obj = Activator.CreateInstance (); while (true) { var field = await protocol.ReadFieldBeginAsync(); if (field.Type == TType.Stop) { break; } var fieldInfo = typeof(TObject).GetField(field.Name); if (fieldInfo != null) { var value = await DeserializeValueAsync(field.Type, protocol); fieldInfo.SetValue(obj, value); } await protocol.ReadFieldEndAsync(); } return obj; }