def formated_response(self, opcode, keylen, extlen, dtype, status, cas, body, opaque, frameextralen): response = { 'vbucket': status, 'opcode': opcode, 'cas': cas, 'opaque': opaque } if opcode == CMD_STREAM_REQ: response = self.format_stream_req(response, status, body) elif opcode == CMD_STREAM_END: response = self.format_stream_end(response, frameextralen, extlen, body) elif opcode == CMD_MUTATION: response = self.format_mutation(response, frameextralen, extlen, body) elif opcode == CMD_DELETION: response = self.format_deletion(response, frameextralen, extlen, body) elif opcode == CMD_EXPIRATION: response = self.format_expiry(response, frameextralen, extlen, body) elif opcode == CMD_SNAPSHOT_MARKER: response = self.format_snapshot_marker(response, frameextralen, extlen, body) elif opcode == CMD_SYSTEM_EVENT: response = self.format_system_event(response, frameextralen, extlen, body) else: assert "Unknown opcode {}".format(opcode) streamId = None if frameextralen: tag, streamId = struct.unpack('>BH', body[0:frameextralen]) assert tag == 0x22 key = body[extlen + frameextralen:extlen + frameextralen + keylen] value = body[extlen + frameextralen + keylen:] xattrs = None if (dtype & DATATYPE_XATTR): total_xattr_len = struct.unpack('>I', value[0:4])[0] xattrs = self.parse_extended_attributes(value[4:], total_xattr_len) value = value[total_xattr_len + 4:] response['xattrs'] = xattrs if opcode in (CMD_EXPIRATION, CMD_DELETION, CMD_MUTATION): if self.collection_filtering and keylen: # Decode the CID from key response['collection_id'], key = decodeCollectionID(key) else: # Belongs to default collection # Should really lookup the CID in the Manifest for _default response['collection_id'] = 0 response['key'] = key response['value'] = value response['streamId'] = streamId return response
def formated_response(self, opcode, keylen, extlen, dtype, status, cas, body, opaque, frameextralen): response = {'vbucket': status, 'opcode' : opcode, 'cas' : cas, 'opaque' : opaque} if opcode == CMD_STREAM_REQ: response = self.format_stream_req(response, status, body) elif opcode == CMD_STREAM_END: response = self.format_stream_end(response, frameextralen, extlen, body) elif opcode == CMD_MUTATION: response = self.format_mutation(response, frameextralen, extlen, body) elif opcode == CMD_DELETION: response = self.format_deletion(response, frameextralen, extlen, body) elif opcode == CMD_EXPIRATION: response = self.format_expiry(response, frameextralen, extlen, body) elif opcode == CMD_SNAPSHOT_MARKER: response = self.format_snapshot_marker(response, frameextralen, extlen, body) elif opcode == CMD_SYSTEM_EVENT: response = self.format_system_event(response, frameextralen, extlen, body) else: assert "Unknown opcode {}".format(opcode) streamId = None if frameextralen: tag, streamId = struct.unpack('>BH', body[0:frameextralen]) assert tag == 0x22 key = body[extlen+frameextralen:extlen+frameextralen+keylen] value = body[extlen+frameextralen+keylen:] xattrs = None if (dtype & DATATYPE_XATTR): total_xattr_len = struct.unpack('>I', value[0:4])[0] xattrs = self.parse_extended_attributes(value[4:], total_xattr_len) value = value[total_xattr_len + 4:] response['xattrs'] = xattrs if opcode in (CMD_EXPIRATION, CMD_DELETION, CMD_MUTATION): if self.collection_filtering and keylen: # Decode the CID from key response['collection_id'], key = decodeCollectionID(key) else: # Belongs to default collection # Should really lookup the CID in the Manifest for _default response['collection_id'] = 0 response['key'] = key response['value'] = value response['streamId'] = streamId return response