import "git.apache.org/thrift.git/lib/go/thrift" protocol := thrift.NewTBinaryProtocolTransport(transport) fieldType, fieldID, err := protocol.ReadFieldBegin() if err != nil { fmt.Println("Error reading field:", err) } defer protocol.ReadFieldEnd() // always call ReadFieldEnd after ReadFieldBegin
import "git.apache.org/thrift.git/lib/go/thrift" protocol := thrift.NewTBinaryProtocolTransport(transport) for { fieldType, fieldID, err := protocol.ReadFieldBegin() if err != nil { fmt.Println("Error reading field:", err) } if fieldType == thrift.STOP { break } defer protocol.ReadFieldEnd() // always call ReadFieldEnd after ReadFieldBegin // process the field data... }In this example, we loop through all the fields in a Thrift message until we reach the "STOP" field type. We use "defer" to make sure we always call "ReadFieldEnd" after reading each field, even if an error occurs. Package library: git.apache.org/thrift.git.lib.go.thrift