Skip to content

Instantly share code, notes, and snippets.

@spikebike
Created April 17, 2012 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spikebike/2405156 to your computer and use it in GitHub Desktop.
Save spikebike/2405156 to your computer and use it in GitHub Desktop.
Attempt to get go, go-protobuf and repeated records working.
package bdr_proto
import proto "code.google.com/p/goprotobuf/proto"
import "math"
// Reference proto and math imports to suppress error if they are not otherwise used.
var _ = proto.GetString
var _ = math.Inf
type Request struct {
Blobarray []*RequestBlob `protobuf:"bytes,1,rep,name=blobarray" json:"blobarray,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *Request) Reset() { *this = Request{} }
func (this *Request) String() string { return proto.CompactTextString(this) }
type RequestBlob struct {
Sha256 *string `protobuf:"bytes,1,req,name=sha256" json:"sha256,omitempty"`
Bsize *int32 `protobuf:"varint,2,req,name=bsize" json:"bsize,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (this *RequestBlob) Reset() { *this = RequestBlob{} }
func (this *RequestBlob) String() string { return proto.CompactTextString(this) }
func init() {
}
package bdr_proto;
message request {
message blob {
required string sha256 = 1;
required int32 bsize = 2;
}
repeated blob blobarray= 1;
}
package main
import (
"./bdr_proto"
"fmt"
)
func main() {
// not sure how to create more than 1 blob message within a single request.
// The bdr_proto.prof file allows it. The protobufs comments at
// http://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/message.h
// seem to claim something like bdr_proto.Add_RequestBlob should work
// the bdr_proto/bdr_proto.pb.go makes no mention of add.
var s1 int32;
var i int32;
str1:="Hello"
s1=1024
// I had hoped just repeating the records would work.
//
// t1:= &bdr_proto.RequestBlob{Sha256: &str1, Bsize: &s1, Sha256: &str2, Bsize: &s2}
Blobarray := make([]bdr_proto.RequestBlob,32)
BlobarrayPtr := make([]*bdr_proto.RequestBlob,32)
t1:= new(bdr_proto.Request)
t1.Blobarray=BlobarrayPtr;
for i =0; i<32; i++ {
fmt.Printf("i=%d\n",i)
// BlobarrayPtr[i]{Sha256: &str1, Bsize: &s1}
// t1.Blobarray[i]=&Blobarray[i];
t1.Blobarray[i]=&Blobarray[i]{Sha256: &str1, Bsize: &s1};
// t1.Blobarray[i].RequestBlob{Sha256: &str1, Bsize: &i}
}
// t1.Blobarray = &Blobarray
t2:= &bdr_proto.RequestBlob{Sha256: &str1, Bsize: &s1}
fmt.Printf("t1 = %+v\n",t1)
fmt.Printf("t2 = %+v\n",t2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment