Skip to content

Commit 9ca5cc0

Browse files
committed
FEAT: bincode: added reading commands: BITSET8, BITSET16 and BITSET32
1 parent ea06082 commit 9ca5cc0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/core/u-bincode.c

+15
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,21 @@ static REBCNT EncodedU32_Size(u32 value) {
915915
}
916916
n++;
917917
break;
918+
case SYM_BITSET8:
919+
n = 1;
920+
goto readBitsetN;
921+
case SYM_BITSET16:
922+
n = 2;
923+
goto readBitsetN;
924+
case SYM_BITSET32:
925+
n = 4;
926+
readBitsetN:
927+
ASSERT_READ_SIZE(value, cp, ep, n);
928+
VAL_SET(temp, REB_BITSET);
929+
bin_new = Copy_Series_Part(bin, VAL_INDEX(buffer_read), n);
930+
VAL_SERIES(temp) = bin_new;
931+
VAL_INDEX(temp) = 0;
932+
break;
918933
case SYM_ENCODEDU32:
919934
ASSERT_READ_SIZE(value, cp, ep, 1);
920935
u = (u64)cp[0];

src/tests/units/bincode-test.r3

+19
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,25 @@ is-protected-error?: func[code][
244244
--assert [0 1 128 129 130 2214768806] = binary/read b [
245245
EncodedU32 EncodedU32 EncodedU32 EncodedU32 EncodedU32 EncodedU32]
246246

247+
--test-- "BinCode - BITSET8, BITSET16, BITSET32 (read)"
248+
binary/read #{81800180000001} [
249+
f8: BITSET8
250+
f16: BITSET16
251+
f32: BITSET32
252+
]
253+
--assert all [
254+
all [f8/0 f8/7]
255+
not any [f8/1 f8/2 f8/3 f8/4 f8/5 f8/6]
256+
]
257+
--assert all [
258+
all [f16/0 f16/15]
259+
not any [f16/1 f16/2 f16/3 f16/4 f16/5 f16/6 f16/7]
260+
]
261+
--assert all [
262+
all [f32/0 f32/31]
263+
not any [f32/1 f32/2 f32/3 f32/4 f32/5 f32/6 f32/7 f32/15]
264+
]
265+
247266
===end-group===
248267

249268

0 commit comments

Comments
 (0)