parent
58335da72a
commit
ced6802007
|
@ -1,2 +1,2 @@
|
||||||
example-protobuf/example-protobuf
|
example-cmd/example-cmd
|
||||||
*.pb.go
|
*.pb.go
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
build:
|
build:
|
||||||
go build
|
go build
|
||||||
./example-protobuf
|
./example-cmd
|
||||||
|
|
||||||
prep:
|
prep:
|
||||||
go get -v -t -u
|
go get -v -t -u
|
||||||
|
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
pb "go.wit.com/lib/protobuf/witProtobuf"
|
"go.wit.com/lib/protobuf/witpb/guipb"
|
||||||
)
|
)
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -23,7 +23,7 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("Error reading file:", err)
|
log.Fatalln("Error reading file:", err)
|
||||||
}
|
}
|
||||||
allEvents := &pb.Event{}
|
allEvents := &guipb.Event{}
|
||||||
if err := proto.Unmarshal(in, allEvents); err != nil {
|
if err := proto.Unmarshal(in, allEvents); err != nil {
|
||||||
log.Error(err, "Failed to parse events:")
|
log.Error(err, "Failed to parse events:")
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ func main() {
|
||||||
log.Println(in)
|
log.Println(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Event) {
|
func marshalWriteToFile(myWriter *bufio.Writer, e *guipb.Event) {
|
||||||
buf, err := proto.Marshal(e)
|
buf, err := proto.Marshal(e)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("marshaling error: ", err)
|
log.Fatal("marshaling error: ", err)
|
||||||
|
@ -60,7 +60,7 @@ func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Event) {
|
||||||
func TestWriteEvent() {
|
func TestWriteEvent() {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
|
||||||
e := pb.CreateSampleEvent()
|
e := guipb.CreateSampleEvent()
|
||||||
|
|
||||||
got := buf.String()
|
got := buf.String()
|
||||||
log.Println(got)
|
log.Println(got)
|
||||||
|
@ -73,13 +73,13 @@ func TestWriteEvent() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func marshalUnmarshal() {
|
func marshalUnmarshal() {
|
||||||
test := pb.CreateSampleEvent()
|
test := guipb.CreateSampleEvent()
|
||||||
data, err := proto.Marshal(test)
|
data, err := proto.Marshal(test)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("marshaling error: ", err)
|
log.Fatal("marshaling error: ", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
newTest := &pb.Event{}
|
newTest := &guipb.Event{}
|
||||||
err = proto.Unmarshal(data, newTest)
|
err = proto.Unmarshal(data, newTest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("unmarshaling error: ", err)
|
log.Fatal("unmarshaling error: ", err)
|
||||||
|
|
Loading…
Reference in New Issue