File tree 2 files changed +32
-0
lines changed
2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -506,6 +506,13 @@ static REBCNT EncodedU32_Size(u32 value) {
506
506
continue ;
507
507
}
508
508
goto error ;
509
+ case SYM_PAD :
510
+ if (IS_INTEGER (next )) {
511
+ i = count % VAL_INT32 (next );
512
+ count += (i > 0 ) ? VAL_INT32 (next ) - i : 0 ;
513
+ continue ;
514
+ }
515
+ goto error ;
509
516
case SYM_BYTES :
510
517
if (IS_BINARY (next )) {
511
518
count += VAL_LEN (next );
@@ -902,6 +909,14 @@ static REBCNT EncodedU32_Size(u32 value) {
902
909
n = 0 ;
903
910
break ;
904
911
912
+ case SYM_PAD :
913
+ n = VAL_INDEX (buffer_write ) % VAL_INT32 (next );
914
+ if (n > 0 ) {
915
+ n = VAL_INT32 (next ) - n ;
916
+ memset (cp , 0 , n );
917
+ }
918
+ break ;
919
+
905
920
case SYM_ENCODEDU32 :
906
921
ASSERT_U32_RANGE (next );
907
922
ulong = VAL_UNT32 (next );
@@ -1476,6 +1491,18 @@ static REBCNT EncodedU32_Size(u32 value) {
1476
1491
VAL_INDEX (buffer_read ) = i ; //TODO: range test
1477
1492
cp = BIN_DATA (bin ) + VAL_INDEX (buffer_read );
1478
1493
continue ;
1494
+ case SYM_PAD :
1495
+ next = ++ value ;
1496
+ if (IS_GET_WORD (next )) next = Get_Var (next );
1497
+ if (!IS_INTEGER (next )) Trap1 (RE_INVALID_SPEC , value );
1498
+ i = VAL_INDEX (buffer_read ) % VAL_INT32 (next );
1499
+ if (i > 0 ) {
1500
+ i = VAL_INT32 (next ) - i ;
1501
+ ASSERT_INDEX_RANGE (buffer_read , i , value );
1502
+ VAL_INDEX (buffer_read ) += i ;
1503
+ cp = BIN_DATA (bin ) + VAL_INDEX (buffer_read );
1504
+ }
1505
+ continue ;
1479
1506
case SYM_SKIPBITS :
1480
1507
next = ++ value ;
1481
1508
if (IS_GET_WORD (next )) next = Get_Var (next );
Original file line number Diff line number Diff line change @@ -230,6 +230,11 @@ is-protected-error?: func[code][
230
230
--assert is-range-error? [binary/read b [AT 1 SKIP 5 UI8]]
231
231
--assert is-range-error? [binary/read b [AT 1 SKIP -1 UI8]]
232
232
233
+ --test-- "BinCode - PAD"
234
+ binary/write b: #{} [UI8 255 PAD 4 UI8 255 ]
235
+ --assert b = #{ FF000000FF }
236
+ --assert [255 255 ] = binary/read b [UI8 PAD 4 UI8]
237
+
233
238
--test-- "BinCode - LENGTH?"
234
239
;LENGTH? returns number of bytes remaining in the buffer
235
240
b: binary #{ 01020304 }
You can’t perform that action at this time.
0 commit comments