def unpack(self, reader): data = Data() (oid, file_size, block_size, version, file_type, num_blocks) = struct.unpack( self.format_str, reader.read(struct.calcsize(self.format_str))) blocks = [] for i in range(num_blocks): (block_id, version, offset, length, serverid, ip, port) = struct.unpack( self.child_format_str, reader.read(struct.calcsize(self.child_format_str))) ip = socket.inet_ntoa(ip) block_data = Data( params={ 'block_id': block_id, 'version': version, 'offset': offset, 'length': length, 'serverid': serverid, 'ip': ip, 'port': port }) blocks.append(block_data) data.oid = oid data.file_size = file_size data.version = version data.block_size = block_size data.file_type = file_type data.blocks = blocks data.type = packet_types.FS_GET_OK return data
def unpack(self, reader): (oid,version,length) = struct.unpack(self.format_str, reader.read(struct.calcsize(self.format_str))) data = Data() data.oid = oid data.version = version data.blocks = {} for i in range(length): (key,val) = struct.unpack(self.child_format_str, reader.read(struct.calcsize(self.child_format_str))) data.blocks[key] = val data.type = packet_types.FS_OID_BLOCKS return data
def unpack(self, reader): (oid, version, length) = struct.unpack(self.format_str, reader.read(struct.calcsize(self.format_str))) data = Data() data.oid = oid data.version = version data.blocks = {} for i in range(length): (key, val) = struct.unpack( self.child_format_str, reader.read(struct.calcsize(self.child_format_str))) data.blocks[key] = val data.type = packet_types.FS_OID_BLOCKS return data
def unpack(self,reader): data = Data() (oid,file_size,block_size, version,file_type,num_blocks) = struct.unpack(self.format_str,reader.read(struct.calcsize(self.format_str))) blocks = [] for i in range(num_blocks): (block_id, version, offset, length, serverid, ip, port) = struct.unpack(self.child_format_str, reader.read(struct.calcsize(self.child_format_str))) ip = socket.inet_ntoa(ip) block_data = Data(params={'block_id':block_id,'version':version,'offset':offset,'length':length,'serverid':serverid,'ip':ip,'port':port}) blocks.append(block_data) data.oid = oid data.file_size = file_size data.version = version data.block_size = block_size data.file_type = file_type data.blocks = blocks data.type = packet_types.FS_GET_OK return data