mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2025-12-08 19:26:19 +00:00
32 lines
628 B
Go
32 lines
628 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
|
|
"example.com/proto/example"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
)
|
|
|
|
func main() {
|
|
test := &example.Test{
|
|
Label: proto.String("hello"),
|
|
Type: proto.Int32(17),
|
|
Reps: []int64{1, 2, 3},
|
|
}
|
|
data, err := proto.Marshal(test)
|
|
if err != nil {
|
|
log.Fatal("marshaling error: ", err)
|
|
}
|
|
newTest := &example.Test{}
|
|
err = proto.Unmarshal(data, newTest)
|
|
if err != nil {
|
|
log.Fatal("unmarshaling error: ", err)
|
|
}
|
|
// Now test and newTest contain the same data.
|
|
if test.GetLabel() != newTest.GetLabel() {
|
|
log.Fatalf("data mismatch %q != %q", test.GetLabel(), newTest.GetLabel())
|
|
}
|
|
// etc.
|
|
}
|