Created
May 27, 2014 18:25
-
-
Save samuel/acf17d45bf6a180f2e06 to your computer and use it in GitHub Desktop.
Example of Thrift struct serialization / deserialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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