Libraryless. Click here for Pure Java version (13227L/76K).
1 | // unsigned values only |
2 | sclass VariableSizeUIntForBitHead is BitIO { |
3 | // How many bits are written at once |
4 | settable int chunkSize = 3; |
5 | |
6 | settable int value; |
7 | |
8 | gettable int bitCount; |
9 | |
10 | public void readWrite(BitHead head) { |
11 | if (head.writeMode()) { |
12 | bitCount = max(1, numberOfBits(value)); |
13 | int value = this.value; |
14 | |
15 | head.writePartialByte(value, chunkSize); |
16 | value >>>= chunkSize; |
17 | |
18 | while (value != 0) { |
19 | head.writeBit(1); |
20 | head.writePartialByte(value, chunkSize); |
21 | value >>>= chunkSize; |
22 | } |
23 | head.writeBit(0); |
24 | } |
25 | |
26 | if (head.readMode()) { |
27 | int value = head.readPartialByte(chunkSize); |
28 | int shift = 0; |
29 | bitCount = chunkSize; |
30 | while (!head.isEOF() && head.readBit()) { |
31 | value |= head.readPartialByte(chunkSize) << bitCount; |
32 | bitCount += chunkSize; |
33 | } |
34 | value(value); |
35 | } |
36 | } |
37 | |
38 | void readWrite(BitHead head, IF0<Int> getter, IVF1<Int> setter) { |
39 | if (head.writeMode()) |
40 | value(getter!); |
41 | readWrite(head); |
42 | if (head.readMode()) |
43 | setter.get(value()); |
44 | } |
45 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1035687 |
Snippet name: | VariableSizeUIntForBitHead |
Eternal ID of this version: | #1035687/5 |
Text MD5: | d574d5aeb646c81b211516e7bfd0a307 |
Transpilation MD5: | d63c2124ecf97c73d24f0941cb6100e5 |
Author: | stefan |
Category: | javax / io |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-07-06 21:51:26 |
Source code size: | 1149 bytes / 45 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 81 / 149 |
Version history: | 4 change(s) |
Referenced in: | [show references] |