示例#1
0
bool Book::Hidratate(ByteString & bookByte){
	int position = 0;

	// id
	this->id = bookByte.readAsInt(position);
	position += sizeof(int);

	//  author
	size_t authorSize = bookByte.readAsInt(position);
	position += sizeof(size_t);
	this->author = (bookByte.read(position, authorSize)).toString();
	position += authorSize;

	// editorial
	size_t editorialSize = bookByte.readAsInt(position);
	position += sizeof(size_t);
	this->editorial = (bookByte.read(position, editorialSize)).toString();
	position += editorialSize;

	// title
	size_t titleSize = bookByte.readAsInt(position);
	position += sizeof(size_t);
	this->title = (bookByte.read(position, titleSize)).toString();
	position += titleSize;

	// text
	size_t textSize = bookByte.readAsInt(position);
	position += sizeof(size_t);
	this->text = (bookByte.read(position, textSize)).toString();
	position += textSize;

	// wordcount
	this->wordCount = bookByte.readAsInt(position);

	return true;
}
示例#2
0
bool Bucket::Hidratate(ByteString &bytesString){
	bool success = true;
	if(int(bytesString.getSize()) != capacity)
	{
		success = false;
	}
	else
	{
		//si tenia registros los borro
		this->toEmpty();

		//Obtiene la Metadata
		dispersionNumber = bytesString.readAsInt(0);

		//Obtiene los registros
		Record* record = NULL;
		ByteString recordBytesString;
		int position = 1*sizeof(int);
		int recordSize = bytesString.readAsInt(1*sizeof(int));
		while(recordSize > 0)
		{
			record = new Record();
			recordBytesString = bytesString.read(position,recordSize);
			record->Hidratate(recordBytesString);
			success = this->insertRecord(record);

			position = position + recordSize;

			//Valida que quede el minimo recordSize que puede tener un registro
			if(position <= capacity - Record::getMinSize())
				recordSize = bytesString.readAsInt(position);
			else
				recordSize = -1;
		}
	}
	return success;
}