public abstract WriteStructBegin ( Thrift.Protocol.TStruct struc ) : void | ||
struc | Thrift.Protocol.TStruct | |
return | void |
using Thrift.Protocol; using System.IO; // Create a new output stream var stream = new MemoryStream(); // Create a new protocol var protocol = new TBinaryProtocol(stream); // Write a struct beginning for a Person object protocol.WriteStructBegin(new TStruct("Person")); // Write some fields for the Person object protocol.WriteFieldBegin(new TField("name", TType.String, 1)); protocol.WriteString("John Doe"); protocol.WriteFieldEnd(); protocol.WriteFieldBegin(new TField("age", TType.I32, 2)); protocol.WriteI32(30); protocol.WriteFieldEnd(); // Write the end of the struct protocol.WriteStructEnd(); // Print the output stream Console.WriteLine(BitConverter.ToString(stream.ToArray()).Replace("-", ""));
using Thrift.Protocol; using System.IO; // Create a new output stream var stream = new MemoryStream(); // Create a new protocol var protocol = new TCompactProtocol(stream); // Write a struct beginning for an Address object protocol.WriteStructBegin(new TStruct("Address")); // Write some fields for the Address object protocol.WriteFieldBegin(new TField("street", TType.String, 1)); protocol.WriteString("123 Main St."); protocol.WriteFieldEnd(); protocol.WriteFieldBegin(new TField("city", TType.String, 2)); protocol.WriteString("Anytown"); protocol.WriteFieldEnd(); protocol.WriteFieldBegin(new TField("state", TType.String, 3)); protocol.WriteString("Anystate"); protocol.WriteFieldEnd(); protocol.WriteFieldBegin(new TField("zip", TType.I32, 4)); protocol.WriteI32(12345); protocol.WriteFieldEnd(); // Write the end of the struct protocol.WriteStructEnd(); // Print the output stream Console.WriteLine(BitConverter.ToString(stream.ToArray()).Replace("-", ""));In this example, we create a new output stream, a new TCompactProtocol, and write the beginning of an Address struct using the WriteStructBegin method. We then write four fields for the Address object using the WriteFieldBegin, the appropriate value methods, and the WriteFieldEnd methods. Finally, we end the struct using the WriteStructEnd method and print the resulting output stream to the console. Package library: Apache Thrift
public abstract WriteStructBegin ( Thrift.Protocol.TStruct struc ) : void | ||
struc | Thrift.Protocol.TStruct | |
return | void |