コード例 #1
0
Block* DictWriter::getEntries() {
	if (currBlock==NULL) {
		readyToOutDict=true;			
		Log::writeToLog("DictWriter", 1, "Data source dry returning NULL");				
		return NULL;
	}
	resetWriter();
	bool writeSuccess=true;
	while (writeSuccess) {	
		ValPos* pair=currBlock->getStartPair();
		//assume int type for now ... fix later
		assert(pair->type == ValPos::INTTYPE);
		if (init) {
			*startPosPtr=pair->position;
			init=false;
		}	
		unsigned int entry;
		if (valueEntryMap.count(*(int*)pair->value)==0) {
			if (numDistinctValues>escapeInt) {
				Log::writeToLog("DictWriter", 5, "Error: number of distinctValues larger than possible to encode in this fieldSize", fieldSize);
				throw new CodingException("Error: number of distinctValues larger than possible to encode in this fieldSize");
			}
			valueEntryMap[*(int*)pair->value]=numDistinctValues;
			entryValueMap[numDistinctValues]=*(int*)pair->value;
			entry=numDistinctValues;
			Log::writeToLog("DictWriter", 1, "No entry for value", *(int*)pair->value);
			Log::writeToLog("DictWriter", 1, "Created entry", numDistinctValues);				
			numDistinctValues++;
		}
		else {
			entry=valueEntryMap[*(int*)pair->value];
			Log::writeToLog("DictWriter", 0, "Writing entry for value", *(int*)pair->value);				
		}
		writeSuccess=bitWriter->writeBits(entry, fieldSize);
		if (writeSuccess) {
			*numValsPtr+=1;				
			Log::writeToLog("DictWriter", 0, "Writing successfully entry", entry);				
			currBlock=(BasicBlock*) blockWriter->getNextValBlock(0);				
			Log::writeToLog("DictWriter", 0, "Got next block");				
			if (currBlock==NULL) {
				Log::writeToLog("DictWriter", 1, "Data source dry returning current buffer (in block)");				
				outBlock->setBuffer(buffer, bfrSizeBits);
				return outBlock;
			}					
		}
	}
	Log::writeToLog("DictWriter", 0, "Filled current buffer, returning it (in block)");				
	outBlock->setBuffer(buffer, bfrSizeBits);
	init=true;
	return outBlock;
		
}
コード例 #2
0
Block* DictMultiWriter::getEntries() {
  if (currBlock==NULL) {
    readyToOutDict=true;			
    Log::writeToLog("DictMultiWriter", 1, "Data source dry returning NULL");				
    return NULL;
  }
  resetWriter();
  bool reusecurrval=false;
  if (currval == NULL) {
    currval = new int[16];
    memset(currval, 0, 64);
  }
  else
    reusecurrval = true;
  bool writeSuccess=true;
  unsigned int numvals;
  unsigned int entry;
  while (writeSuccess) {
    entry = 0;	
    /*	Pair* pair=currBlock->getStartPair();
	if (init) {
	*startPosPtr=pair->position;
	init=false;
	}	
	unsigned int entry;*/
    if (reusecurrval) {
      numvals=numEncodedValsInInt;
      reusecurrval=false;
    }
    else
      numvals = getEntry(currval);
    
    for (unsigned int j = 0; j < numvals; j++) {
      if (valueEntryMap.count(currval[j])==0) {
	if ((int)numDistinctValues>(1<<fieldSize)) {
	  throw new CodingException("Error: number of distinctValues larger than possible to encode in this fieldSize");
	}
	valueEntryMap[currval[j]]=numDistinctValues;
	entryValueMap[numDistinctValues]=currval[j];
	/*currval = new int[16];
	  memset(currval, 0, 64);*/
	entry = setEntry(entry, j, numDistinctValues);
	numDistinctValues++;
      }
      else {
	entry = setEntry(entry, j,valueEntryMap[currval[j]]);
      }
    }
    writeSuccess=false;
    
      switch(fieldBytes) {
      case 1:
      writeSuccess=byteWriter->writeByte((byte)entry);
      break;
      case 2:
      writeSuccess=byteWriter->writeShort((unsigned short)entry);
      break;
      /*case 24:
      writeSuccess=byteWriter->writeThree(entry);
      break;
      case 32:
      writeSuccess=byteWriter->writeInt(entry);
      break;*/
      default: throw new UnexpectedException("Should be 1 or 2");
      }
    
    //writeSuccess=byteWriter->writeInt(entry);
    if (writeSuccess) {
      *numValsPtr+=numvals;		
      
      //Log::writeToLog("DictMultiWriter", 0, "Writing successfully entry", entry);				
      //currBlock=(BasicBlock*) blockWriter->getNextValBlock(0);				
      //Log::writeToLog("DictMultiWriter", 0, "Got next block");				
      if (currBlock==NULL) {
	Log::writeToLog("DictMultiWriter", 1, "Data source dry returning current buffer (in block)");				
	outBlock->setBuffer(buffer, bfrSizeBits);
	return outBlock;
      }					
    }
    //}
    /*else {
      writeSuccess=false;
      writeSuccess=byteWriter->writeInt(currval[0]);
      for (unsigned int i = 1; i < numvals; i++)
      writeSuccess&=byteWriter->writeInt(currval[i]);
      
      if (writeSuccess) {
      *numValsPtr+=numvals;				
      outBlock->setBuffer(buffer, bfrSizeBits);
      return outBlock;
      }
      else throw new UnimplementedException("Haven't dealt with this case yet");
      }*/
  }
  //Log::writeToLog("DictMultiWriter", 0, "Filled current buffer, returning it (in block)");				
  outBlock->setBuffer(buffer, bfrSizeBits);
  init=true;
  return outBlock;
  
}
コード例 #3
0
ファイル: PacketSerializer.cpp プロジェクト: 21451061/Lifes
PacketSerializer::PacketSerializer(size_t n): 
	buff_len(n) {
	base_ptr = allocator.allocate(n);
	resetReader();
	resetWriter();
}