diff options
Diffstat (limited to 'src/rawblock.nim')
-rw-r--r-- | src/rawblock.nim | 22 |
1 files changed, 11 insertions, 11 deletions
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 @@ | |||
14 | # You should have received a copy of the GNU Affero General Public License | 14 | # You should have received a copy of the GNU Affero General Public License |
15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. | 15 | # along with this program. If not, see <https://www.gnu.org/licenses/>. |
16 | 16 | ||
17 | import integers, bitstream | 17 | import integers, bitreader, bitwriter |
18 | 18 | ||
19 | const maxDataBitLength = 100_000_000 * wordBitLength # 100MB | 19 | const maxDataBitLength = 100_000_000 * wordBitLength # 100MB |
20 | const bitLengthFieldBitLength = 2 * wordBitLength | 20 | const bitLengthFieldBitLength = 2 * wordBitLength |
@@ -23,18 +23,18 @@ type RawBlock* = object | |||
23 | bitLength: int | 23 | bitLength: int |
24 | data: seq[uint8] | 24 | data: seq[uint8] |
25 | 25 | ||
26 | proc readSerialised*(bitStream: BitStream): RawBlock = | 26 | proc readSerialised*(bitReader: BitReader): RawBlock = |
27 | let bitLength = bitStream.readBits(bitLengthFieldBitLength, uint16).int | 27 | let bitLength = bitReader.readBits(bitLengthFieldBitLength, uint16).int |
28 | let data = readSeq(bitStream, bitLength, uint8) | 28 | let data = readSeq(bitReader, bitLength, uint8) |
29 | RawBlock(bitLength: bitLength, data: data.data) | 29 | RawBlock(bitLength: bitLength, data: data.data) |
30 | 30 | ||
31 | proc writeSerialisedTo*(rawBlock: RawBlock, bitStream: BitStream) = | 31 | proc writeSerialisedTo*(rawBlock: RawBlock, bitWriter: BitWriter) = |
32 | bitStream.writeBits(bitLengthFieldBitLength, rawBlock.bitLength.uint16) | 32 | bitWriter.writeBits(bitLengthFieldBitLength, rawBlock.bitLength.uint16) |
33 | writeSeq(bitStream, rawBlock.bitLength, rawBlock.data) | 33 | bitWriter.writeSeq(rawBlock.bitLength, rawBlock.data) |
34 | 34 | ||
35 | proc readRaw*(bitStream: BitStream, bits: int = maxDataBitLength): RawBlock = | 35 | proc readRaw*(bitReader: BitReader, bits: int = maxDataBitLength): RawBlock = |
36 | let data = readSeq(bitStream, bits, uint8) | 36 | let data = readSeq(bitReader, bits, uint8) |
37 | RawBlock(bitLength: data.bitLength, data: data.data) | 37 | RawBlock(bitLength: data.bitLength, data: data.data) |
38 | 38 | ||
39 | proc writeRawTo*(rawBlock: RawBlock, bitStream: BitStream) = | 39 | proc writeRawTo*(rawBlock: RawBlock, bitWriter: BitWriter) = |
40 | writeSeq(bitStream, rawBlock.bitLength, rawBlock.data) | 40 | bitWriter.writeSeq(rawBlock.bitLength, rawBlock.data) |