Created
October 14, 2010 02:36
-
-
Save also/625440 to your computer and use it in GitHub Desktop.
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
import struct | |
import json | |
import sys | |
class RDQ(object): | |
def __init__(self, f): | |
self.f = f | |
self.read = f.read | |
def read_str_short(self): | |
l = struct.unpack('>H', self.f.read(2))[0] | |
return self.read(l) | |
def read_str(self): | |
l = struct.unpack('>I', self.f.read(4))[0] | |
return self.read(l) | |
def main(name): | |
with open(name) as f: | |
rdq = RDQ(f) | |
# read some header junk | |
rdq.read(36) | |
while True: | |
pos = f.tell() | |
'basic_message' | |
item_type = rdq.read_str_short() | |
if len(item_type) == 0: | |
break | |
'resource' | |
rdq.read(3) | |
rdq.read_str_short() | |
'exchange' | |
rdq.read(7) | |
rdq.read_str_short() | |
exchange = rdq.read(3) | |
rdq.read_str_short() | |
rdq.read(3) | |
queue = rdq.read_str_short() | |
'content' | |
rdq.read(3) | |
rdq.read_str_short() | |
'none' | |
rdq.read(3) | |
rdq.read_str_short() | |
rdq.read(6) | |
content_type = rdq.read_str_short() | |
rdq.read(7) | |
content = rdq.read_str() | |
rdq.read(66) | |
print json.dumps({'pos': pos, 'queue': queue, 'content_type': content_type, 'content': content}) | |
if __name__ == '__main__': | |
main(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment