// unsigned values only sclass VariableSizeUIntForBitHead is BitIO { // How many bits are written at once settable int chunkSize = 3; settable int value; gettable int bitCount; public void readWrite(BitHead head) { if (head.writeMode()) { bitCount = max(1, numberOfBits(value)); int value = this.value; head.writePartialByte(value, chunkSize); value >>>= chunkSize; while (value != 0) { head.writeBit(1); head.writePartialByte(value, chunkSize); value >>>= chunkSize; } head.writeBit(0); } if (head.readMode()) { int value = head.readPartialByte(chunkSize); int shift = 0; bitCount = chunkSize; while (!head.isEOF() && head.readBit()) { value |= head.readPartialByte(chunkSize) << bitCount; bitCount += chunkSize; } value(value); } } void readWrite(BitHead head, IF0 getter, IVF1 setter) { if (head.writeMode()) value(getter!); readWrite(head); if (head.readMode()) setter.get(value()); } }