io.binary.fast: remove duplication.
parent
d7775b150e
commit
980fba617d
|
@ -37,20 +37,22 @@ MACRO: reassemble-le ( n -- quot ) le-range reassemble-bytes ;
|
||||||
:: n-le> ( bytes n -- x )
|
:: n-le> ( bytes n -- x )
|
||||||
bytes n check-length drop n firstn-unsafe n reassemble-le ; inline
|
bytes n check-length drop n firstn-unsafe n reassemble-le ; inline
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
: if-endian ( endian bytes seq -- )
|
||||||
|
[
|
||||||
|
compute-native-endianness =
|
||||||
|
[ dup byte-array? ] [ f ] if
|
||||||
|
] 2dip if ; inline
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
: 2be> ( bytes -- x )
|
: 2be> ( bytes -- x )
|
||||||
compute-native-endianness big-endian =
|
big-endian [ c:short deref ] [ 2 n-be> ] if-endian ;
|
||||||
[ dup byte-array? ] [ f ] if
|
|
||||||
[ c:short deref ] [ 2 n-be> ] if ;
|
|
||||||
|
|
||||||
: 4be> ( bytes -- x )
|
: 4be> ( bytes -- x )
|
||||||
compute-native-endianness big-endian =
|
big-endian [ c:int deref ] [ 4 n-be> ] if-endian ;
|
||||||
[ dup byte-array? ] [ f ] if
|
|
||||||
[ c:int deref ] [ 4 n-be> ] if ;
|
|
||||||
|
|
||||||
: 8be> ( bytes -- x )
|
: 8be> ( bytes -- x )
|
||||||
compute-native-endianness big-endian =
|
big-endian [ c:longlong deref ] [ 8 n-be> ] if-endian ;
|
||||||
[ dup byte-array? ] [ f ] if
|
|
||||||
[ c:longlong deref ] [ 8 n-be> ] if ;
|
|
||||||
|
|
||||||
: be> ( bytes -- x )
|
: be> ( bytes -- x )
|
||||||
dup length {
|
dup length {
|
||||||
|
@ -61,19 +63,13 @@ MACRO: reassemble-le ( n -- quot ) le-range reassemble-bytes ;
|
||||||
} case ;
|
} case ;
|
||||||
|
|
||||||
: 2le> ( bytes -- x )
|
: 2le> ( bytes -- x )
|
||||||
compute-native-endianness little-endian =
|
little-endian [ c:short deref ] [ 2 n-le> ] if-endian ;
|
||||||
[ dup byte-array? ] [ f ] if
|
|
||||||
[ c:short deref ] [ 2 n-le> ] if ;
|
|
||||||
|
|
||||||
: 4le> ( bytes -- x )
|
: 4le> ( bytes -- x )
|
||||||
compute-native-endianness little-endian =
|
little-endian [ c:int deref ] [ 4 n-le> ] if-endian ;
|
||||||
[ dup byte-array? ] [ f ] if
|
|
||||||
[ c:int deref ] [ 4 n-le> ] if ;
|
|
||||||
|
|
||||||
: 8le> ( bytes -- x )
|
: 8le> ( bytes -- x )
|
||||||
compute-native-endianness little-endian =
|
little-endian [ c:longlong deref ] [ 8 n-le> ] if-endian ;
|
||||||
[ dup byte-array? ] [ f ] if
|
|
||||||
[ c:longlong deref ] [ 8 n-le> ] if ;
|
|
||||||
|
|
||||||
: le> ( bytes -- x )
|
: le> ( bytes -- x )
|
||||||
dup length {
|
dup length {
|
||||||
|
|
Loading…
Reference in New Issue