-
-
Save kylelemons/2410270 to your computer and use it in GitHub Desktop.
example for protobuf, go, and the repeated protobuf entry
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 bdr_proto; | |
message request { | |
message blob { | |
required string hash = 1; // the sha256 checksum of the blob | |
required int32 size = 2; // the size of the blob | |
} | |
repeated blob blobs = 1; | |
} |
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 ( | |
"./bdr_proto" | |
"crypto/sha256" | |
"fmt" | |
) | |
import M "math/rand" | |
import C "crypto/rand" | |
func main() { | |
req := &blob_proto.Request{} | |
for i = 0; i < 32; i++ { | |
// read in 16 bytes from /dev/urandom to sha256 | |
randBytes = make([]byte, 16) | |
C.Read(randBytes) | |
// get its size | |
size := int32(len(randBytes)) | |
// create a new hash, and do a crypty hash of the random bytes. | |
sha := sha256.New() | |
sha.Write(randBytes) | |
hash := fmt.Sprintf("%x", hash.Sum(nil)) | |
req.Blobs = append(req.Blobs, &blob_proto.RequestBlob{ | |
Hash: &hash, | |
Size: &size, | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment