Skip to content

Instantly share code, notes, and snippets.

@laiyonghao
Created April 26, 2012 13:40
Show Gist options
  • Save laiyonghao/2499696 to your computer and use it in GitHub Desktop.
Save laiyonghao/2499696 to your computer and use it in GitHub Desktop.
abu.rpc request encode
#!/usr/bin/env python
import struct
import abu.rpc.rpc_pb2 as rpc
import echo_pb2 as echo
PYLOAD = 'hello' * 30
def new():
arg = echo.Packet(text = PYLOAD)
req = rpc.Request()
req.method = 'echo'
req.request = arg.SerializeToString()
pkt = rpc.Packet()
pkt.type = rpc.REQUEST
pkt.identify = 100
pkt.serialized = req.SerializeToString()
buff = pkt.SerializeToString()
packed_buff_len = struct.pack('!I', len(buff))
return packed_buff_len + buff
for i in xrange(10000):
new()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment