diff options
Diffstat (limited to 'src/streamblock.nim')
-rw-r--r-- | src/streamblock.nim | 37 |
1 files changed, 19 insertions, 18 deletions
diff --git a/src/streamblock.nim b/src/streamblock.nim index 8d2b4b1..eef916f 100644 --- a/src/streamblock.nim +++ b/src/streamblock.nim | |||
@@ -15,7 +15,8 @@ | |||
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 sequtils | 17 | import sequtils |
18 | import integers, bitstream, rawblock, lzssblock | 18 | import integers, bitreader, bitwriter |
19 | import rawblock, lzssblock | ||
19 | 20 | ||
20 | type BlockKind* = enum | 21 | type BlockKind* = enum |
21 | uncompressed = 0b00'u8, | 22 | uncompressed = 0b00'u8, |
@@ -33,32 +34,32 @@ type StreamBlock* = object | |||
33 | else: | 34 | else: |
34 | discard | 35 | discard |
35 | 36 | ||
36 | proc readSerialised*(bitStream: BitStream): StreamBlock = | 37 | proc readSerialised*(bitReader: BitReader): StreamBlock = |
37 | result.last = bitStream.readBool() | 38 | result.last = bitReader.readBool() |
38 | result.kind = bitStream.readBits(2, uint8).BlockKind | 39 | result.kind = bitReader.readBits(2, uint8).BlockKind |
39 | case result.kind: | 40 | case result.kind: |
40 | of uncompressed: result.rawBlock = rawblock.readRaw(bitStream) | 41 | of uncompressed: result.rawBlock = rawblock.readRaw(bitReader) |
41 | of lzss: result.lzssBlock = lzssblock.readRaw(bitStream) | 42 | of lzss: result.lzssBlock = lzssblock.readRaw(bitReader) |
42 | else: raise newException(ValueError, "unhandled block type") | 43 | else: raise newException(ValueError, "unhandled block type") |
43 | 44 | ||
44 | proc writeSerialisedTo*(streamBlock: StreamBlock, bitStream: BitStream) = | 45 | proc writeSerialisedTo*(streamBlock: StreamBlock, bitWriter: BitWriter) = |
45 | bitStream.writeBool(streamBlock.last) | 46 | bitWriter.writeBool(streamBlock.last) |
46 | bitStream.writeBits(2, streamBlock.kind.uint8) | 47 | bitWriter.writeBits(2, streamBlock.kind.uint8) |
47 | case streamBlock.kind: | 48 | case streamBlock.kind: |
48 | of uncompressed: streamBlock.rawBlock.writeSerialisedTo(bitStream) | 49 | of uncompressed: streamBlock.rawBlock.writeSerialisedTo(bitWriter) |
49 | of lzss: streamBlock.lzssBlock.writeSerialisedTo(bitStream) | 50 | of lzss: streamBlock.lzssBlock.writeSerialisedTo(bitWriter) |
50 | else: raise newException(ValueError, "unhandled block type") | 51 | else: raise newException(ValueError, "unhandled block type") |
51 | 52 | ||
52 | proc readRaw*(bitStream: BitStream, kind: BlockKind = uncompressed): StreamBlock = | 53 | proc readRaw*(bitReader: BitReader, kind: BlockKind = uncompressed): StreamBlock = |
53 | result.kind = kind | 54 | result.kind = kind |
54 | case kind: | 55 | case kind: |
55 | of uncompressed: result.rawBlock = rawblock.readRaw(bitStream) | 56 | of uncompressed: result.rawBlock = rawblock.readRaw(bitReader) |
56 | of lzss: result.lzssBlock = lzssblock.readRaw(bitStream) | 57 | of lzss: result.lzssBlock = lzssblock.readRaw(bitReader) |
57 | else: raise newException(ValueError, "unhandled block type") | 58 | else: raise newException(ValueError, "unhandled block type") |
58 | result.last = bitStream.atEnd() | 59 | result.last = bitReader.atEnd() |
59 | 60 | ||
60 | proc writeRawTo*(streamBlock: StreamBlock, bitStream: BitStream) = | 61 | proc writeRawTo*(streamBlock: StreamBlock, bitWriter: BitWriter) = |
61 | case streamBlock.kind: | 62 | case streamBlock.kind: |
62 | of uncompressed: streamBlock.rawBlock.writeRawTo(bitStream) | 63 | of uncompressed: streamBlock.rawBlock.writeRawTo(bitWriter) |
63 | of lzss: streamBlock.lzssBlock.writeRawTo(bitStream) | 64 | of lzss: streamBlock.lzssBlock.writeRawTo(bitWriter) |
64 | else: raise newException(ValueError, "unhandled block type") | 65 | else: raise newException(ValueError, "unhandled block type") |