import ( "bytes" "github.com/apesternikov/thrift4go/lib/go/src/thrift" ) func serializeMyStruct(myStruct *MyStruct) ([]byte, error) { var buffer bytes.Buffer protocol := thrift.NewTBinaryProtocol(&buffer) err := myStruct.Write(protocol) if err != nil { return nil, err } return buffer.Bytes(), nil }
import ( "bytes" "github.com/apesternikov/thrift4go/lib/go/src/thrift" ) func deserializeMyStruct(data []byte) (*MyStruct, error) { var buffer bytes.Buffer buffer.Write(data) protocol := thrift.NewTBinaryProtocol(&buffer) myStruct := &MyStruct{} err := myStruct.Read(protocol) if err != nil { return nil, err } return myStruct, nil }In this example, we create a new TBinaryProtocol object and pass it a bytes.Buffer object containing our serialized data. We then call the Read method on a new instance of our Thrift struct to deserialize it from binary format.