From d9768cd0315b0415d20818de9c897c6168c95b78 Mon Sep 17 00:00:00 2001 From: pacien Date: Fri, 23 Nov 2018 12:57:00 +0100 Subject: Split bitstream into bitreader and bitwriter --- src/rawblock.nim | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/rawblock.nim') diff --git a/src/rawblock.nim b/src/rawblock.nim index bdbfc71..aa3e7ae 100644 --- a/src/rawblock.nim +++ b/src/rawblock.nim @@ -14,7 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -import integers, bitstream +import integers, bitreader, bitwriter const maxDataBitLength = 100_000_000 * wordBitLength # 100MB const bitLengthFieldBitLength = 2 * wordBitLength @@ -23,18 +23,18 @@ type RawBlock* = object bitLength: int data: seq[uint8] -proc readSerialised*(bitStream: BitStream): RawBlock = - let bitLength = bitStream.readBits(bitLengthFieldBitLength, uint16).int - let data = readSeq(bitStream, bitLength, uint8) +proc readSerialised*(bitReader: BitReader): RawBlock = + let bitLength = bitReader.readBits(bitLengthFieldBitLength, uint16).int + let data = readSeq(bitReader, bitLength, uint8) RawBlock(bitLength: bitLength, data: data.data) -proc writeSerialisedTo*(rawBlock: RawBlock, bitStream: BitStream) = - bitStream.writeBits(bitLengthFieldBitLength, rawBlock.bitLength.uint16) - writeSeq(bitStream, rawBlock.bitLength, rawBlock.data) +proc writeSerialisedTo*(rawBlock: RawBlock, bitWriter: BitWriter) = + bitWriter.writeBits(bitLengthFieldBitLength, rawBlock.bitLength.uint16) + bitWriter.writeSeq(rawBlock.bitLength, rawBlock.data) -proc readRaw*(bitStream: BitStream, bits: int = maxDataBitLength): RawBlock = - let data = readSeq(bitStream, bits, uint8) +proc readRaw*(bitReader: BitReader, bits: int = maxDataBitLength): RawBlock = + let data = readSeq(bitReader, bits, uint8) RawBlock(bitLength: data.bitLength, data: data.data) -proc writeRawTo*(rawBlock: RawBlock, bitStream: BitStream) = - writeSeq(bitStream, rawBlock.bitLength, rawBlock.data) +proc writeRawTo*(rawBlock: RawBlock, bitWriter: BitWriter) = + bitWriter.writeSeq(rawBlock.bitLength, rawBlock.data) -- cgit v1.2.3