Skip to content

Instantly share code, notes, and snippets.

@sigmonsays
Created November 1, 2011 00:50
Show Gist options
  • Save sigmonsays/11c6f1b509770b848a52 to your computer and use it in GitHub Desktop.
Save sigmonsays/11c6f1b509770b848a52 to your computer and use it in GitHub Desktop.
##### FILE: test.proto
package test;
enum OpCode {
OP_ONE = 1;
OP_TWO = 2;
}
message Message {
// this works
// optional int32 op = 1 [ default = 1 ] ;
// this does not work
optional OpCode op = 1 [ default = OP_TWO ];
}
##### FILE: test.py
#!/usr/bin/env python
import time
from lwpb.codec import MessageCodec
pb2file = './test.pb2'
codec = MessageCodec( pb2file=pb2file, typename='test.Message')
cnt = 10
for n in [1,2]:
print n
# Iteration completes yet fails is strange ways.
sum([ n for n in xrange(cnt) ])
t = time.time()
print 'hello', cnt
for n in xrange(cnt):
# encode
m = {
'foo' : 'foo.1' }
bin = codec.encode(m)
# decode
#m2 = codec.decode(bin)
#td = time.time() - t
#print '%d in %.2f sec' % (10, td)
print 'done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment