protocol := thrift.NewTBinaryProtocolTransport(socket) protocol.WriteI32(42)
type MyStruct struct { Foo int32 Bar string } func (m *MyStruct) Write(output thrift.TProtocol) error { if err := output.WriteStructBegin("MyStruct"); err != nil { return err } if err := output.WriteFieldBegin("Foo", thrift.I32, 1); err != nil { return err } if err := output.WriteI32(m.Foo); err != nil { return err } if err := output.WriteFieldEnd(); err != nil { return err } if err := output.WriteFieldBegin("Bar", thrift.STRING, 2); err != nil { return err } if err := output.WriteString(m.Bar); err != nil { return err } if err := output.WriteFieldEnd(); err != nil { return err } if err := output.WriteFieldStop(); err != nil { return err } if err := output.WriteStructEnd(); err != nil { return err } return nil } myStruct := &MyStruct{ Foo: 42, Bar: "Hello world!", } protocol := thrift.NewTBinaryProtocolTransport(socket) myStruct.Write(protocol)In this example, we define a custom struct, MyStruct, which implements the Write method of the thrift.TProtocol interface. This method uses the WriteI32 method to write the Foo field of the struct to the protocol. We then create an instance of MyStruct with some sample data, create a TBinaryProtocol instance, and call the Write method on our struct to write it to the protocol. Overall, the git.apache.org.thrift.git.lib.go.thrift TProtocol package provides a convenient set of functions for working with Thrift protocols in Go.