def encode(): for i in range(500): t = Test() t.a = 2147483647 t.b = 9223372036854775807 t.c = 2147483647 t.d = 9223372036854775807 t.e = 4294967295 t.f = 18446744073709551615 t.g = 2147483647 t.h = 9223372036854775807 t.i = 0.3 t.j = 0.3 t.k = 4294967295 t.l = 18446744073709551615 t.m = u'测试' t.n = True t.o.a = 150 t.o.b = -150 t.p.append(1) t.p.append(2) t.p.append(3) t.q.append(1) t.q.append(2) t.q.append(3) r = t.r.add() r.a = 150 r.b = -150 r = t.r.add() r.a = 150 r.b = -150 t.s = TYPE2 t.SerializeToString()
from test_pb2 import Test t = Test( sha1="thesha", a=911111, b=-911111, c=-911111, d=911111111111111, e=-911111111111111, f=-911111111111111, ) t.bars.append(8) t.bars.append(5) t.bars.append(0) print t open("gen", "wb").write(t.SerializeToString())