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): (file_type, path, block_size, replicas) = struct.unpack(self.format_str, reader.read(struct.calcsize(self.format_str))) data = Data() data.file_type = file_type data.path = self._short_string(path) #self._short_string(path) data.block_size = block_size data.replicas = replicas data.type = packet_types.FS_CREATE return data
def unpack(self, reader): (file_type, path, block_size, replicas) = struct.unpack( self.format_str, reader.read(struct.calcsize(self.format_str))) data = Data() data.file_type = file_type data.path = self._short_string(path) #self._short_string(path) data.block_size = block_size data.replicas = replicas data.type = packet_types.FS_CREATE 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