diff --git a/example-protobuf/main.go b/example-protobuf/main.go index df751a2..1705e70 100644 --- a/example-protobuf/main.go +++ b/example-protobuf/main.go @@ -51,17 +51,7 @@ func marshalWriteToFile(myWriter *bufio.Writer, e *pb.Event) { func TestWriteEvent() { buf := new(bytes.Buffer) - // [START populate_proto] - e := &pb.Event{ - Id: 1234, - Name: "jcarrEvent1", - Email: "jcarr@wit.com", - Results: []*pb.Event_Response{ - {Name: "foobar", Type: pb.Event_ADD}, - }, - } - // [END populate_proto] - + e := pb.CreateSampleEvent() e.Id += 1 e.Name = "jcarrEvent2" @@ -76,14 +66,7 @@ func TestWriteEvent() { } func marshalUnmarshal() { - test := &pb.Event{ - Id: 1234, - Name: "jcarrEvent1", - Email: "jcarr@wit.com", - Results: []*pb.Event_Response{ - {Name: "555-4321", Type: pb.Event_ADD}, - }, - } + test := pb.CreateSampleEvent() data, err := proto.Marshal(test) if err != nil { log.Fatal("marshaling error: ", err) diff --git a/sampleData.go b/sampleData.go new file mode 100644 index 0000000..3a2ffe0 --- /dev/null +++ b/sampleData.go @@ -0,0 +1,27 @@ +package witProtobuf + +import "log" +// import "bytes" +// import "os" +// import "bufio" +// import "io" +// import "io/ioutil" + +func CreateSampleEvent() *Event { + // TODO: flush this out to do all the fields + log.Println("CreateSampleEvent() is generating a example protobuf Event") + + e := &Event{ + Id: 1234, + Name: "jcarrEvent1", + Email: "jcarr@wit.com", + Results: []*Event_Response{ + {Name: "foobar", Type: Event_ADD}, + }, + } + + e.Id += 1 + e.Name = "jcarrEvent2" + + return e +}