import ( "github.com.apesternikov.thrift4go.lib.go.src.thrift" "github.com.apesternikov.thrift4go.lib.go.src.thrift/protocol" ) func serializeStruct(s MyStruct) []byte { trans := thrift.NewMemoryBuffer() proto := protocol.NewBinaryProtocol(trans) proto.WriteFieldBegin("field1", thrift.STRING, 1) proto.WriteString(s.Field1) proto.WriteFieldBegin("field2", thrift.I32, 2) proto.WriteI32(s.Field2) proto.WriteFieldEnd() // end of field2 proto.WriteFieldEnd() // end of struct return trans.Bytes() }In this example, we are using a struct called `MyStruct` that has two fields: `Field1` (a string) and `Field2` (an integer). We create a new `MemoryBuffer` to hold the serialized data, and create a new `BinaryProtocol` to handle the serialization. We then use the `WriteFieldBegin` method to start writing the fields to the output stream, and use `WriteString` and `WriteI32` to write the actual data. Finally, we use `WriteFieldEnd` to mark the end of each field and the end of the struct. Overall, this library provides a convenient way to work with Thrift messages in Go.