Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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])
Add Comment
Please, Sign In to add comment