Skip to content

Instantly share code, notes, and snippets.

@samuel
Created May 27, 2014 18:25
Show Gist options
  • Save samuel/acf17d45bf6a180f2e06 to your computer and use it in GitHub Desktop.
Save samuel/acf17d45bf6a180f2e06 to your computer and use it in GitHub Desktop.
Example of Thrift struct serialization / deserialization
package main
import (
"bytes"
"log"
"github.com/samuel/go-thrift/thrift"
)
type testStruct struct {
SomeString string `thrift:"1"`
}
func main() {
si := testStruct{SomeString: "abc"}
b := &bytes.Buffer{}
pw := thrift.NewBinaryProtocolWriter(b, true)
if err := thrift.EncodeStruct(pw, si); err != nil {
log.Fatal(err)
}
var so testStruct
pr := thrift.NewBinaryProtocolReader(b, false)
if err := thrift.DecodeStruct(pr, &so); err != nil {
log.Fatal(err)
}
if si.SomeString != so.SomeString {
log.Fatalf("'%s' != '%s'", si.SomeString, so.SomeString)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment