///////////////////////////////////////////////////////////////////////////
	// Read the next N bits, for use when all the bits are not in memory.
	// Inptus:
	//	int				nbrBits			The number of bits to read.
	// Outputs:
	//	unsigned char*	returnBuffer	Filled with the bits read, starting
	//									with the LSB of the first byte
	// Return value:
	//	int			The number of bits actually read
	///////////////////////////////////////////////////////////////////////////
	int BitStreamRead::SlowReadBits(
		int nbrBits,
		unsigned char* returnBuffer
	) {
		int bitsRemain = nbrBits;
		BitPtr outPtr(returnBuffer, 0);
		while (bitsRemain > 0) {
			int availBits = endPtr - current;
			if (availBits > bitsRemain) {
				availBits = bitsRemain;
			}
			bitsRemain -= availBits;
			// TODO: Optimize the bit copy using bytewise shift/mask
			while (availBits != 0) {
				*outPtr = (int)*current;
				availBits--;
				++current;
				++outPtr;
			}
			if (bitsRemain > 0) {
				// Fill the buffer again.
				int bytesRead = byteReader->Read(bufferSize, buffer);
				current = startPtr;
				endPtr = startPtr + bytesRead * 8;
				if (bytesRead == 0) {
					break;
				}
			}
		}
		return nbrBits - bitsRemain;
	}
Esempio n. 2
0
void convertSSBPipedFile(const std::string &tblFolder) {
  StopWatch watch;
  watch.init();
  scoped_array<char> inPtr(new char[IO_BUFFER_SIZE]);
  scoped_array<char> outPtr(new char[IO_BUFFER_SIZE]);
  char *inb = inPtr.get();
  char *outb = outPtr.get();
  convertOneSSBPipedFile<Customer>(inb, outb, tblFolder, "customer");
  convertOneSSBPipedFile<Date>(inb, outb, tblFolder, "date");
  convertOneSSBPipedFile<Lineorder>(inb, outb, tblFolder, "lineorder");
  convertOneSSBPipedFile<Part>(inb, outb, tblFolder, "part");
  convertOneSSBPipedFile<Supplier>(inb, outb, tblFolder, "supplier");
#ifndef _MSC_VER
  ::sync ();
#endif
  watch.stop();
  LOG(INFO) << "converted all SSB tbl files to bin files. " << watch.getElapsed() << " micsosec";
}