def decode_payload(self, payload): """Decode a Kafka message payload chunk stream.""" bytestream = io.BytesIO(payload) chunk = Chunk(bytestream, align=False) if chunk.getname() != JSON_CHUNK_TYPE: print('Error: Each Agent message must start with a JSON chunk') return {} json_message = chunk.read().decode('utf-8') message = json.loads(json_message) chunk.close() blobs = [] while True: try: chunk = Chunk(bytestream, align=False) except EOFError: break if chunk.getname() == BLOB_CHUNK_TYPE: blobs.append(chunk.read()) chunk.close() message[BLOBS] = blobs return message
def parseFromFile(cls, iFile, nodeName = None): # parse a file generating an SF2 tree structure # read stuff from file at the current position aChunk = Chunk(iFile, align=True, bigendian=False) ckID = aChunk.getname() ckSize = aChunk.getsize() ckData = aChunk.read() aChunk.close() # let's create a node from this data node = SF2Parser.createNode(nodeName, ckID, ckSize, ckData) # depending on the type of node, children could be inside of it SF2Parser.parseNode(node) # return the root node return node
def parseFromFile(cls, iFile, nodeName=None): # parse a file generating an SF2 tree structure # read stuff from file at the current position aChunk = Chunk(iFile, align=True, bigendian=False) ckID = aChunk.getname() ckSize = aChunk.getsize() ckData = aChunk.read() aChunk.close() # let's create a node from this data node = SF2Parser.createNode(nodeName, ckID, ckSize, ckData) # depending on the type of node, children could be inside of it SF2Parser.parseNode(node) # return the root node return node
def blorb_find_debug_chunk(filename): file = open(filename, 'rb') formchunk = Chunk(file) formchunk = formchunk if (formchunk.getname() != b'FORM'): raise Exception('This does not appear to be a Blorb file.') formtype = formchunk.read(4) if (formtype != b'IFRS'): raise Exception('This does not appear to be a Blorb file.') chunks = [] debugchunk = None formlen = formchunk.getsize() while formchunk.tell() < formlen: chunk = Chunk(formchunk) start = formchunk.tell() size = chunk.getsize() formtype = None if chunk.getname() == b'FORM': formtype = chunk.read(4) subchunk = BlorbChunk(formchunk, chunk.getname(), start, size, formtype) chunks.append(subchunk) chunk.skip() chunk.close() for chunk in chunks: if (chunk.type == b'Dbug'): debugchunk = chunk formchunk.close() file.close() file = None return debugchunk