protocol := thrift.NewBinaryProtocol(transport) protocol.WriteStructBegin("Person") protocol.WriteFieldBegin("name", thrift.STRING, 1) protocol.WriteString(p.Name) protocol.WriteFieldEnd() protocol.WriteFieldBegin("age", thrift.I32, 2) protocol.WriteI32(p.Age) protocol.WriteFieldEnd() protocol.WriteStructEnd()
func WriteMessage(protocol thrift.TProtocol, method string, seqID int32, args interface{}) error { protocol.WriteMessageBegin(method, thrift.CALL, seqID) err := thrift.NewTSerializer().Write(args, protocol) if err != nil { return err } protocol.WriteMessageEnd() return protocol.Flush() }In this example, we are using the WriteFieldEnd method indirectly by calling the WriteMessage method, which serializes a Thrift message into a TProtocol. At each field boundary, the TSerializer library will call the WriteFieldEnd method to mark the end of the field. Overall, the git.apache.org.thrift.git.lib.go.thrift TProtocol package provides a powerful and flexible way to serialize and deserialize Thrift messages using various protocols and data types.