@@ -45,6 +45,24 @@ library Packing {
45
45
}
46
46
}
47
47
48
+ function pack_2_4 (bytes2 left , bytes4 right ) internal pure returns (bytes6 result ) {
49
+ assembly ("memory-safe" ) {
50
+ result := or (left, shr (16 , right))
51
+ }
52
+ }
53
+
54
+ function pack_2_6 (bytes2 left , bytes6 right ) internal pure returns (bytes8 result ) {
55
+ assembly ("memory-safe" ) {
56
+ result := or (left, shr (16 , right))
57
+ }
58
+ }
59
+
60
+ function pack_4_2 (bytes4 left , bytes2 right ) internal pure returns (bytes6 result ) {
61
+ assembly ("memory-safe" ) {
62
+ result := or (left, shr (32 , right))
63
+ }
64
+ }
65
+
48
66
function pack_4_4 (bytes4 left , bytes4 right ) internal pure returns (bytes8 result ) {
49
67
assembly ("memory-safe" ) {
50
68
result := or (left, shr (32 , right))
@@ -87,6 +105,18 @@ library Packing {
87
105
}
88
106
}
89
107
108
+ function pack_6_2 (bytes6 left , bytes2 right ) internal pure returns (bytes8 result ) {
109
+ assembly ("memory-safe" ) {
110
+ result := or (left, shr (48 , right))
111
+ }
112
+ }
113
+
114
+ function pack_6_6 (bytes6 left , bytes6 right ) internal pure returns (bytes12 result ) {
115
+ assembly ("memory-safe" ) {
116
+ result := or (left, shr (48 , right))
117
+ }
118
+ }
119
+
90
120
function pack_8_4 (bytes8 left , bytes4 right ) internal pure returns (bytes12 result ) {
91
121
assembly ("memory-safe" ) {
92
122
result := or (left, shr (64 , right))
@@ -255,6 +285,48 @@ library Packing {
255
285
}
256
286
}
257
287
288
+ function extract_6_1 (bytes6 self , uint8 offset ) internal pure returns (bytes1 result ) {
289
+ if (offset > 5 ) revert OutOfRangeAccess ();
290
+ assembly ("memory-safe" ) {
291
+ result := and (shl (mul (8 , offset), self), shl (248 , not (0 )))
292
+ }
293
+ }
294
+
295
+ function replace_6_1 (bytes6 self , bytes1 value , uint8 offset ) internal pure returns (bytes6 result ) {
296
+ bytes1 oldValue = extract_6_1 (self, offset);
297
+ assembly ("memory-safe" ) {
298
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
299
+ }
300
+ }
301
+
302
+ function extract_6_2 (bytes6 self , uint8 offset ) internal pure returns (bytes2 result ) {
303
+ if (offset > 4 ) revert OutOfRangeAccess ();
304
+ assembly ("memory-safe" ) {
305
+ result := and (shl (mul (8 , offset), self), shl (240 , not (0 )))
306
+ }
307
+ }
308
+
309
+ function replace_6_2 (bytes6 self , bytes2 value , uint8 offset ) internal pure returns (bytes6 result ) {
310
+ bytes2 oldValue = extract_6_2 (self, offset);
311
+ assembly ("memory-safe" ) {
312
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
313
+ }
314
+ }
315
+
316
+ function extract_6_4 (bytes6 self , uint8 offset ) internal pure returns (bytes4 result ) {
317
+ if (offset > 2 ) revert OutOfRangeAccess ();
318
+ assembly ("memory-safe" ) {
319
+ result := and (shl (mul (8 , offset), self), shl (224 , not (0 )))
320
+ }
321
+ }
322
+
323
+ function replace_6_4 (bytes6 self , bytes4 value , uint8 offset ) internal pure returns (bytes6 result ) {
324
+ bytes4 oldValue = extract_6_4 (self, offset);
325
+ assembly ("memory-safe" ) {
326
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
327
+ }
328
+ }
329
+
258
330
function extract_8_1 (bytes8 self , uint8 offset ) internal pure returns (bytes1 result ) {
259
331
if (offset > 7 ) revert OutOfRangeAccess ();
260
332
assembly ("memory-safe" ) {
@@ -297,6 +369,20 @@ library Packing {
297
369
}
298
370
}
299
371
372
+ function extract_8_6 (bytes8 self , uint8 offset ) internal pure returns (bytes6 result ) {
373
+ if (offset > 2 ) revert OutOfRangeAccess ();
374
+ assembly ("memory-safe" ) {
375
+ result := and (shl (mul (8 , offset), self), shl (208 , not (0 )))
376
+ }
377
+ }
378
+
379
+ function replace_8_6 (bytes8 self , bytes6 value , uint8 offset ) internal pure returns (bytes8 result ) {
380
+ bytes6 oldValue = extract_8_6 (self, offset);
381
+ assembly ("memory-safe" ) {
382
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
383
+ }
384
+ }
385
+
300
386
function extract_12_1 (bytes12 self , uint8 offset ) internal pure returns (bytes1 result ) {
301
387
if (offset > 11 ) revert OutOfRangeAccess ();
302
388
assembly ("memory-safe" ) {
@@ -339,6 +425,20 @@ library Packing {
339
425
}
340
426
}
341
427
428
+ function extract_12_6 (bytes12 self , uint8 offset ) internal pure returns (bytes6 result ) {
429
+ if (offset > 6 ) revert OutOfRangeAccess ();
430
+ assembly ("memory-safe" ) {
431
+ result := and (shl (mul (8 , offset), self), shl (208 , not (0 )))
432
+ }
433
+ }
434
+
435
+ function replace_12_6 (bytes12 self , bytes6 value , uint8 offset ) internal pure returns (bytes12 result ) {
436
+ bytes6 oldValue = extract_12_6 (self, offset);
437
+ assembly ("memory-safe" ) {
438
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
439
+ }
440
+ }
441
+
342
442
function extract_12_8 (bytes12 self , uint8 offset ) internal pure returns (bytes8 result ) {
343
443
if (offset > 4 ) revert OutOfRangeAccess ();
344
444
assembly ("memory-safe" ) {
@@ -395,6 +495,20 @@ library Packing {
395
495
}
396
496
}
397
497
498
+ function extract_16_6 (bytes16 self , uint8 offset ) internal pure returns (bytes6 result ) {
499
+ if (offset > 10 ) revert OutOfRangeAccess ();
500
+ assembly ("memory-safe" ) {
501
+ result := and (shl (mul (8 , offset), self), shl (208 , not (0 )))
502
+ }
503
+ }
504
+
505
+ function replace_16_6 (bytes16 self , bytes6 value , uint8 offset ) internal pure returns (bytes16 result ) {
506
+ bytes6 oldValue = extract_16_6 (self, offset);
507
+ assembly ("memory-safe" ) {
508
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
509
+ }
510
+ }
511
+
398
512
function extract_16_8 (bytes16 self , uint8 offset ) internal pure returns (bytes8 result ) {
399
513
if (offset > 8 ) revert OutOfRangeAccess ();
400
514
assembly ("memory-safe" ) {
@@ -465,6 +579,20 @@ library Packing {
465
579
}
466
580
}
467
581
582
+ function extract_20_6 (bytes20 self , uint8 offset ) internal pure returns (bytes6 result ) {
583
+ if (offset > 14 ) revert OutOfRangeAccess ();
584
+ assembly ("memory-safe" ) {
585
+ result := and (shl (mul (8 , offset), self), shl (208 , not (0 )))
586
+ }
587
+ }
588
+
589
+ function replace_20_6 (bytes20 self , bytes6 value , uint8 offset ) internal pure returns (bytes20 result ) {
590
+ bytes6 oldValue = extract_20_6 (self, offset);
591
+ assembly ("memory-safe" ) {
592
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
593
+ }
594
+ }
595
+
468
596
function extract_20_8 (bytes20 self , uint8 offset ) internal pure returns (bytes8 result ) {
469
597
if (offset > 12 ) revert OutOfRangeAccess ();
470
598
assembly ("memory-safe" ) {
@@ -549,6 +677,20 @@ library Packing {
549
677
}
550
678
}
551
679
680
+ function extract_24_6 (bytes24 self , uint8 offset ) internal pure returns (bytes6 result ) {
681
+ if (offset > 18 ) revert OutOfRangeAccess ();
682
+ assembly ("memory-safe" ) {
683
+ result := and (shl (mul (8 , offset), self), shl (208 , not (0 )))
684
+ }
685
+ }
686
+
687
+ function replace_24_6 (bytes24 self , bytes6 value , uint8 offset ) internal pure returns (bytes24 result ) {
688
+ bytes6 oldValue = extract_24_6 (self, offset);
689
+ assembly ("memory-safe" ) {
690
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
691
+ }
692
+ }
693
+
552
694
function extract_24_8 (bytes24 self , uint8 offset ) internal pure returns (bytes8 result ) {
553
695
if (offset > 16 ) revert OutOfRangeAccess ();
554
696
assembly ("memory-safe" ) {
@@ -647,6 +789,20 @@ library Packing {
647
789
}
648
790
}
649
791
792
+ function extract_28_6 (bytes28 self , uint8 offset ) internal pure returns (bytes6 result ) {
793
+ if (offset > 22 ) revert OutOfRangeAccess ();
794
+ assembly ("memory-safe" ) {
795
+ result := and (shl (mul (8 , offset), self), shl (208 , not (0 )))
796
+ }
797
+ }
798
+
799
+ function replace_28_6 (bytes28 self , bytes6 value , uint8 offset ) internal pure returns (bytes28 result ) {
800
+ bytes6 oldValue = extract_28_6 (self, offset);
801
+ assembly ("memory-safe" ) {
802
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
803
+ }
804
+ }
805
+
650
806
function extract_28_8 (bytes28 self , uint8 offset ) internal pure returns (bytes8 result ) {
651
807
if (offset > 20 ) revert OutOfRangeAccess ();
652
808
assembly ("memory-safe" ) {
@@ -759,6 +915,20 @@ library Packing {
759
915
}
760
916
}
761
917
918
+ function extract_32_6 (bytes32 self , uint8 offset ) internal pure returns (bytes6 result ) {
919
+ if (offset > 26 ) revert OutOfRangeAccess ();
920
+ assembly ("memory-safe" ) {
921
+ result := and (shl (mul (8 , offset), self), shl (208 , not (0 )))
922
+ }
923
+ }
924
+
925
+ function replace_32_6 (bytes32 self , bytes6 value , uint8 offset ) internal pure returns (bytes32 result ) {
926
+ bytes6 oldValue = extract_32_6 (self, offset);
927
+ assembly ("memory-safe" ) {
928
+ result := xor (self, shr (mul (8 , offset), xor (oldValue, value)))
929
+ }
930
+ }
931
+
762
932
function extract_32_8 (bytes32 self , uint8 offset ) internal pure returns (bytes8 result ) {
763
933
if (offset > 24 ) revert OutOfRangeAccess ();
764
934
assembly ("memory-safe" ) {
0 commit comments