! Copyright (C) 2007, 2011 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors alien alien.accessors byte-arrays io.binary
+USING: accessors alien alien.accessors byte-arrays endian
kernel kernel.private math math.bitwise parser sequences
sequences.private vocabs.loader ;
IN: bit-arrays
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors byte-arrays byte-vectors
-combinators.short-circuit io.binary kernel math math.bitwise
+combinators.short-circuit endian kernel math math.bitwise
sequences sequences.private ;
IN: bitstreams
classes.builtin classes.private classes.tuple
classes.tuple.private combinators combinators.short-circuit
combinators.smart command-line compiler.codegen.relocation
-compiler.units generic generic.single.private grouping
-hashtables hashtables.private io io.binary io.encodings.binary
-io.files io.pathnames kernel kernel.private layouts make math
-math.order namespaces namespaces.private parser parser.notes
-prettyprint quotations sequences sequences.private source-files
-splitting strings system vectors vocabs words ;
+compiler.units endian generic generic.single.private grouping
+hashtables hashtables.private io io.encodings.binary io.files
+io.pathnames kernel kernel.private layouts make math
+math.bitwise math.order namespaces namespaces.private parser
+parser.notes prettyprint quotations sequences sequences.private
+source-files splitting strings system vectors vocabs words ;
IN: bootstrap.image
: arch-name ( os cpu -- arch )
! See http://factorcode.org/license.txt for BSD license
USING: accessors arrays assocs base64 byte-arrays calendar
-calendar.format calendar.parser combinators io io.binary
+calendar.format calendar.parser combinators endian io
io.encodings.binary io.encodings.string io.encodings.utf8
io.streams.byte-array io.streams.string kernel math math.bitwise
math.floats.half present sequences strings urls ;
! Copyright (C) 2006, 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors byte-arrays byte-vectors checksums grouping
-io.binary kernel locals make math sequences ;
+USING: accessors byte-arrays byte-vectors checksums endian
+grouping kernel locals make math sequences ;
IN: checksums.common
: calculate-pad-length ( length -- length' )
! Copyright (C) 2016 Alexander Ilin.
! See http://factorcode.org/license.txt for BSD license.
-USING: checksums io.binary kernel math sequences
-sequences.private ;
+USING: checksums endian kernel math sequences sequences.private ;
IN: checksums.crc16
CONSTANT: crc16-polynomial 0xa001
: (crc16) ( crc ch -- crc )
dupd bitxor
- mask-byte crc16-table nth-unsafe
+ 0xff bitand crc16-table nth-unsafe
swap -8 shift bitxor ; inline
SINGLETON: crc16
! Copyright (C) 2013 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: checksums grouping io.binary kernel locals math sequences
+USING: checksums endian grouping kernel locals math sequences
;
IN: checksums.fletcher
! Copyright (C) 2010 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: checksums grouping io.binary kernel math sequences ;
+USING: checksums endian grouping kernel math sequences ;
IN: checksums.internet
! Copyright (C) 2018 John Benediktsson.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data byte-arrays checksums
-combinators grouping io.binary kernel locals math math.bitwise
+combinators endian grouping kernel locals math math.bitwise
sequences specialized-arrays ;
SPECIALIZED-ARRAY: uint64_t
SPECIALIZED-ARRAY: uint32_t
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data byte-arrays
-checksums fry grouping io.binary kernel math math.bitwise
+checksums endian fry grouping kernel math math.bitwise
math.ranges sequences ;
IN: checksums.murmur
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types arrays checksums checksums.common
-combinators combinators.smart fry grouping io.binary kernel
+combinators combinators.smart endian fry grouping kernel
kernel.private literals locals math math.bitwise math.ranges
sequences sequences.generalizations sequences.private
specialized-arrays ;
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data byte-arrays
-checksums combinators fry grouping io.binary kernel math
+checksums combinators endian fry grouping kernel math
math.bitwise math.ranges sequences sequences.private ;
IN: checksums.superfast
! See http://factorcode.org/license.txt for BSD license
USING: accessors alien.c-types alien.data byte-arrays checksums
-grouping io.binary kernel literals math math.bitwise math.order
+endian grouping kernel literals math math.bitwise math.order
sequences sequences.generalizations sequences.private
specialized-arrays ;
SPECIALIZED-ARRAY: uint64_t
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data byte-arrays
-checksums combinators generalizations grouping io.binary kernel
+checksums combinators endian generalizations grouping kernel
locals math math.bitwise math.ranges sequences
specialized-arrays ;
SPECIALIZED-ARRAY: uint64_t
compiler.cfg.utilities compiler.cfg.value-numbering.graph
compiler.cfg.value-numbering.math
compiler.cfg.value-numbering.rewrite cpu.architecture
-generalizations grouping io.binary kernel locals make math
+endian generalizations grouping kernel locals make math
sequences ;
IN: compiler.cfg.value-numbering.simd
! Copyright (C) 2009, 2020 Marc Fauconneau, Abtin Molavi, Jacob Fischer.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs byte-vectors combinators
-combinators.smart compression.huffman fry hashtables io.binary
+combinators.smart compression.huffman endian fry hashtables
kernel literals locals math math.bitwise math.order math.ranges
sequences sorting memoize combinators.short-circuit byte-arrays ;
QUALIFIED-WITH: bitstreams bs
! Copyright (C) 2011 Erik Charlebois.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel namespaces words math math.order locals math.bitwise io.binary make ;
+USING: kernel namespaces words math math.order locals
+math.bitwise endian make ;
IN: cpu.ppc.assembler
! This vocabulary implements the V2.06B Power ISA found at http://www.power.org.
! Copyright (C) 2005, 2010 Slava Pestov, Joe Groff.
! See http://factorcode.org/license.txt for BSD license.
-USING: arrays io.binary kernel combinators
+USING: arrays endian kernel combinators
combinators.short-circuit math math.bitwise locals namespaces
make sequences words system layouts math.order accessors
cpu.x86.assembler.operands cpu.x86.assembler.operands.private ;
USING: cpu.x86.features tools.test kernel sequences math math.order
-strings system io.binary ;
+strings system endian ;
IN: cpu.x86.features.tests
[ t ] [ sse-version 0 42 between? ] unit-test
! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.enums alien.syntax arrays calendar
-combinators combinators.smart constructors destructors grouping
-io io.binary io.encodings.binary io.encodings.string
+combinators combinators.smart constructors destructors endian
+grouping io io.encodings.binary io.encodings.string
io.encodings.utf8 io.sockets io.sockets.private
io.streams.byte-array io.timeouts kernel make math math.bitwise
math.parser namespaces random sequences slots.syntax splitting
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: endian kernel namespaces tools.test ;
+USING: classes endian endian.private kernel math namespaces tools.test ;
{ t } [ [ endianness get big-endian = ] with-big-endian ] unit-test
{ t } [ [ endianness get little-endian = ] with-little-endian ] unit-test
+
+{ 0x0102 } [ B{ 01 02 } 2be> ] unit-test
+{ 0x01020304 } [ B{ 01 02 03 04 } 4be> ] unit-test
+{ 0x0102030405060708 } [ B{ 01 02 03 04 05 06 07 08 } 8be> ] unit-test
+
+{ 0x0102 } [ B{ 02 01 } 2le> ] unit-test
+{ 0x01020304 } [ B{ 04 03 02 01 } 4le> ] unit-test
+{ 0x0102030405060708 } [ B{ 08 07 06 05 04 03 02 01 } 8le> ] unit-test
+
+{ 0x7a2c793b2ff08554 } [
+ B{ 0x54 0x85 0xf0 0x2f 0x3b 0x79 0x2c 0x7a } le>
+] unit-test
+
+{ 0x988a259c3433f237 } [
+ B{ 0x37 0xf2 0x33 0x34 0x9c 0x25 0x8a 0x98 } le>
+] unit-test
+
+{ 0x03020100 } [ B{ 0 1 2 3 } le> ] unit-test
+{ 0x00010203 } [ B{ 0 1 2 3 } be> ] unit-test
+
+{ 0x332211 } [
+ B{ 0x11 0x22 0x33 } le>
+] unit-test
+
+{ 0x04030201 } [ B{ 1 2 3 4 } signed-le> ] unit-test
+{ 0x01020304 } [ B{ 1 2 3 4 } signed-be> ] unit-test
+
+{ -12 } [ B{ 0xf4 0xff 0xff 0xff } signed-le> ] unit-test
+{ -12 } [ B{ 0xff 0xff 0xff 0xf4 } signed-be> ] unit-test
+
+{ B{ 0 0 4 0xd2 } } [ 1234 4 >be ] unit-test
+{ B{ 0 0 0 0 0 0 4 0xd2 } } [ 1234 8 >be ] unit-test
+{ B{ 0xd2 4 0 0 } } [ 1234 4 >le ] unit-test
+{ B{ 0xd2 4 0 0 0 0 0 0 } } [ 1234 8 >le ] unit-test
+
+{ 1234 } [ 1234 4 >be be> ] unit-test
+{ 1234 } [ 1234 4 >le le> ] unit-test
+
+{ fixnum } [ B{ 0 0 0 0 0 0 0 0 0 0 } be> class-of ] unit-test
+
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.data grouping io.binary kernel
+
+USING: alien.c-types alien.data byte-arrays combinators
+combinators.smart endian kernel math math.ranges sequences
+sequences.generalizations ;
+
+USING: alien.c-types alien.data grouping kernel
math.bitwise namespaces sequences ;
+
IN: endian
SINGLETONS: big-endian little-endian ;
: compute-native-endianness ( -- class )
1 int <ref> char deref 0 = big-endian little-endian ? ; foldable
+<PRIVATE
+
+: slow-be> ( seq -- x ) 0 [ [ 8 shift ] dip + ] reduce ;
+
+: slow-le> ( seq -- x ) 0 [ 8 * shift + ] reduce-index ;
+
+ERROR: bad-length bytes n ;
+
+: check-length ( bytes n -- bytes n )
+ 2dup [ length ] dip > [ bad-length ] when ; inline
+
+<<
+: be-range ( n -- range )
+ 1 - 8 * 0 -8 <range> ; inline
+
+: le-range ( n -- range )
+ 1 - 8 * 0 swap 8 <range> ; inline
+
+: reassemble-bytes ( range -- quot )
+ [ [ [ ] ] [ '[ _ shift ] ] if-zero ] map
+ '[ [ _ spread ] [ bitor ] reduce-outputs ] ; inline
+
+MACRO: reassemble-be ( n -- quot ) be-range reassemble-bytes ;
+
+MACRO: reassemble-le ( n -- quot ) le-range reassemble-bytes ;
+>>
+
+:: n-be> ( bytes n -- x )
+ bytes n check-length drop n firstn-unsafe n reassemble-be ; inline
+
+:: n-le> ( bytes n -- x )
+ bytes n check-length drop n firstn-unsafe n reassemble-le ; inline
+
+! HINTS: n-be> { byte-array object } ;
+! HINTS: n-le> { byte-array object } ;
+
+! { >le >be } [
+! { { fixnum fixnum } { bignum fixnum } }
+! set-specializer
+! ] each
+
+! { le> be> } [
+! { byte-array } set-specializer
+! ] each
+
+: if-endian ( endian bytes-quot seq-quot -- )
+ [
+ compute-native-endianness =
+ [ dup byte-array? ] [ f ] if
+ ] 2dip if ; inline
+
+: 2be> ( bytes -- x )
+ big-endian [ uint16_t deref ] [ 2 n-be> ] if-endian ;
+
+: 4be> ( bytes -- x )
+ big-endian [ uint32_t deref ] [ 4 n-be> ] if-endian ;
+
+: 8be> ( bytes -- x )
+ big-endian [ uint64_t deref ] [ 8 n-be> ] if-endian ;
+
+: 2le> ( bytes -- x )
+ little-endian [ uint16_t deref ] [ 2 n-le> ] if-endian ;
+
+: 4le> ( bytes -- x )
+ little-endian [ uint32_t deref ] [ 4 n-le> ] if-endian ;
+
+: 8le> ( bytes -- x )
+ little-endian [ uint64_t deref ] [ 8 n-le> ] if-endian ;
+
+PRIVATE>
+
+: be> ( bytes -- x )
+ dup length {
+ { 2 [ 2be> ] }
+ { 4 [ 4be> ] }
+ { 8 [ 8be> ] }
+ [ drop slow-be> ]
+ } case ;
+
+: le> ( bytes -- x )
+ dup length {
+ { 2 [ 2le> ] }
+ { 4 [ 4le> ] }
+ { 8 [ 8le> ] }
+ [ drop slow-le> ]
+ } case ;
+
+<PRIVATE
+
+: signed> ( x seq -- n )
+ length 8 * 2dup 1 - bit? [ 2^ - ] [ drop ] if ; inline
+
+: slow-signed-le> ( bytes -- x ) [ le> ] [ signed> ] bi ;
+
+: slow-signed-be> ( bytes -- x ) [ be> ] [ signed> ] bi ;
+
+PRIVATE>
+
+: signed-be> ( bytes -- x )
+ big-endian [
+ dup length {
+ { 2 [ int16_t deref ] }
+ { 4 [ int32_t deref ] }
+ { 8 [ int64_t deref ] }
+ [ drop slow-signed-be> ]
+ } case
+ ] [ slow-signed-be> ] if-endian ;
+
+: signed-le> ( bytes -- x )
+ little-endian [
+ dup length {
+ { 2 [ int16_t deref ] }
+ { 4 [ int32_t deref ] }
+ { 8 [ int64_t deref ] }
+ [ drop slow-signed-le> ]
+ } case
+ ] [ slow-signed-le> ] if-endian ;
+
+: nth-byte ( x n -- b ) -8 * shift 0xff bitand ; inline
+
+<PRIVATE
+
+: map-bytes ( x seq -- byte-array )
+ [ nth-byte ] with B{ } map-as ; inline
+
+: >slow-be ( x n -- byte-array ) <iota> <reversed> map-bytes ;
+
+: >slow-le ( x n -- byte-array ) <iota> map-bytes ;
+
+PRIVATE>
+
+: >le ( x n -- bytes )
+ compute-native-endianness little-endian = [
+ {
+ { 2 [ int16_t <ref> ] }
+ { 4 [ int32_t <ref> ] }
+ { 8 [ int64_t <ref> ] }
+ [ >slow-le ]
+ } case
+ ] [ >slow-le ] if ;
+
+: >be ( x n -- bytes )
+ compute-native-endianness big-endian = [
+ {
+ { 2 [ int16_t <ref> ] }
+ { 4 [ int32_t <ref> ] }
+ { 8 [ int64_t <ref> ] }
+ [ >slow-be ]
+ } case
+ ] [ >slow-be ] if ;
+
SYMBOL: native-endianness
native-endianness [ compute-native-endianness ] initialize
-SYMBOL: endianness
-endianness [ native-endianness get-global ] initialize
-
HOOK: >native-endian native-endianness ( obj n -- bytes )
M: big-endian >native-endian >be ;
M: little-endian unsigned-native-endian> le> ;
+SYMBOL: endianness
+endianness [ native-endianness get-global ] initialize
+
: signed-native-endian> ( obj n -- n' )
[ unsigned-native-endian> ] dip >signed ;
M: little-endian unsigned-endian> le> ;
-: signed-endian> ( obj n -- bytes )
- [ unsigned-endian> ] dip >signed ;
+HOOK: signed-endian> endianness ( obj -- bytes )
+
+M: big-endian signed-endian> signed-be> ;
+
+M: little-endian signed-endian> signed-le> ;
: with-endianness ( endian quot -- )
[ endianness ] dip with-variable ; inline
'[ le> _ >be ] map
] if concat
] if ; inline
+
! Copyright (c) 2008, 2010 Slava Pestov
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs namespaces kernel sequences sets
-destructors combinators fry logging io.encodings.utf8
-io.encodings.string io.binary io.sockets.secure random checksums
+destructors combinators endian fry logging io.encodings.utf8
+io.encodings.string io.sockets.secure random checksums
checksums.sha urls
html.forms
http.server
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs byte-arrays byte-vectors classes
combinators definitions fry generic generic.single
-generic.standard hashtables io.binary kernel kernel.private math
+generic.standard hashtables kernel kernel.private math
math.parser parser sbufs sequences sequences.private splitting
strings vectors words ;
IN: hints
\ assoc-stack { vector } set-specializer
-{ >le >be } [
- { { fixnum fixnum } { bignum fixnum } }
- set-specializer
-] each
-
-{ le> be> } [
- { byte-array } set-specializer
-] each
-
\ base> { string fixnum } set-specializer
M\ hashtable at*
! Copyright (C) 2009 Daniel Ehrenberg, Jonghyouk Yun.
! See http://factorcode.org/license.txt for BSD license.
-USING: kernel io.encodings accessors assocs sequences biassocs generic
-math.order simple-flat-file io io.binary byte-arrays locals combinators
-words classes.singleton fry classes.parser parser quotations ;
+USING: accessors assocs biassocs byte-arrays classes.parser
+classes.singleton combinators endian generic io io.encodings
+kernel math.bitwise math.order parser sequences simple-flat-file
+words ;
IN: io.encodings.euc
TUPLE: euc { table biassoc read-only } ;
USING: xml xml.data kernel io io.encodings interval-maps splitting fry
math.parser sequences combinators assocs locals accessors math arrays
byte-arrays ascii io.files biassocs math.order namespaces
-combinators.short-circuit io.binary io.encodings.iana ;
+combinators.short-circuit endian io.encodings.iana ;
FROM: io.encodings.ascii => ascii ;
IN: io.encodings.gb18030
! Copyright (C) 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs biassocs byte-arrays combinators
-combinators.short-circuit io io.binary io.encodings kernel
-literals locals math namespaces sequences simple-flat-file ;
+combinators.short-circuit endian io io.encodings kernel
+literals math math.bitwise namespaces sequences simple-flat-file ;
IN: io.encodings.iso2022
SINGLETON: iso2022
! Copyright (C) 2009 Daniel Ehrenberg
! See http://factorcode.org/license.txt for BSD license.
-USING: sequences kernel io io.files combinators.short-circuit
-math.order assocs io.encodings io.binary fry strings math
-io.encodings.ascii arrays byte-arrays accessors splitting
-math.parser biassocs io.encodings.iana namespaces
-locals multiline combinators simple-flat-file ;
+USING: accessors arrays assocs byte-arrays
+combinators.short-circuit endian io io.encodings
+io.encodings.iana kernel math.bitwise math.order namespaces
+simple-flat-file ;
IN: io.encodings.shift-jis
SINGLETON: shift-jis
! Copyright (C) 2009 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
-USING: math kernel io.encodings combinators io io.encodings.utf16
-sequences io.binary io.encodings.iana ;
+USING: combinators endian math io io.encodings
+io.encodings.iana io.encodings.utf16 kernel sequences ;
IN: io.encodings.utf32
SINGLETON: utf32be
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data alien.strings
alien.syntax arrays ascii assocs classes.struct combinators
-combinators.short-circuit continuations destructors environment io
-io.backend io.binary io.buffers io.files io.files.private
-io.files.types io.pathnames io.pathnames.private io.ports io.streams.c
-io.streams.null io.timeouts kernel libc literals locals math math.bitwise
-namespaces sequences specialized-arrays system threads tr vectors windows
-windows.errors windows.handles windows.kernel32 windows.shell32
-windows.time windows.types windows.winsock splitting ;
+combinators.short-circuit continuations destructors environment
+io io.backend io.buffers io.files io.files.private
+io.files.types io.pathnames io.pathnames.private io.ports
+io.streams.c io.streams.null io.timeouts kernel libc literals
+locals math math.bitwise namespaces sequences specialized-arrays
+system threads tr vectors windows windows.errors windows.handles
+windows.kernel32 windows.shell32 windows.time windows.types
+windows.winsock splitting ;
SPECIALIZED-ARRAY: ushort
IN: io.files.windows
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data alien.enums
alien.strings assocs byte-arrays classes.struct combinators
-combinators.short-circuit destructors io io.backend io.binary
+combinators.short-circuit destructors endian io io.backend
io.buffers io.encodings.latin1 io.encodings.string
io.encodings.utf8 io.files io.pathnames io.ports io.sockets
io.sockets.secure io.timeouts kernel libc math math.functions
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data alien.strings arrays
byte-arrays classes classes.struct combinators
-combinators.short-circuit continuations destructors fry
-grouping init io.backend io.binary io.encodings.ascii
+combinators.short-circuit continuations destructors endian fry
+grouping init io.backend io.encodings.ascii
io.encodings.binary io.pathnames io.ports io.streams.duplex
kernel locals math math.parser memoize namespaces present
sequences sequences.private splitting strings summary system
}
} ;
+HELP: d>w/w
+{ $values { "d" "a 64-bit integer" } { "w1" "a 32-bit integer" } { "w2" "a 32-bit integer" } }
+{ $description "Outputs two integers, the least followed by the most significant 32 bits of the input." } ;
+
+HELP: w>h/h
+{ $values { "w" "a 32-bit integer" } { "h1" "a 16-bit integer" } { "h2" "a 16-bit integer" } }
+{ $description "Outputs two integers, the least followed by the most significant 16 bits of the input." } ;
+
+HELP: h>b/b
+{ $values { "h" "a 16-bit integer" } { "b1" "an 8-bit integer" } { "b2" "an 8-bit integer" } }
+{ $description "Outputs two integers, the least followed by the most significant 8 bits of the input." } ;
+
ARTICLE: "math-bitfields" "Constructing bit fields"
"Some applications, such as binary communication protocols and assemblers, need to construct integers from elaborate bit field specifications. Hand-coding this using " { $link shift } " and " { $link bitor } " results in repetitive code. A higher-level facility exists to factor out this repetition:"
{ $subsections bitfield } ;
W-
W*
}
+"Words for taking larger integers apart into smaller integers:"
+{ $subsections
+ d>w/w
+ w>h/h
+ h>b/b
+}
"Converting a number to the nearest even/odd/signed:"
{ $subsections
>even
{ 3 } [ 0b101 bit-length ] unit-test
{ 3 } [ 0b110 bit-length ] unit-test
{ 3 } [ 0b111 bit-length ] unit-test
+
+{ 0x56780000 0x12340000 } [ 0x1234000056780000 d>w/w ] unit-test
+{ 0x5678 0x1234 } [ 0x12345678 w>h/h ] unit-test
+{ 0x34 0x12 } [ 0x1234 h>b/b ] unit-test
: even-parity? ( obj -- ? ) bit-count even? ;
: odd-parity? ( obj -- ? ) bit-count odd? ;
+
+: d>w/w ( d -- w1 w2 )
+ [ 0xffffffff bitand ] [ -32 shift 0xffffffff bitand ] bi ;
+
+: w>h/h ( w -- h1 h2 )
+ [ 0xffff bitand ] [ -16 shift 0xffff bitand ] bi ;
+
+: h>b/b ( h -- b1 b2 )
+ [ 0xff bitand ] [ -8 shift 0xff bitand ] bi ;
! Copyright (C) 2013 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: arrays assocs byte-arrays combinators grouping hashtables
-io io.binary io.encodings io.encodings.binary
+USING: arrays assocs byte-arrays combinators endian grouping
+hashtables io io.encodings io.encodings.binary
io.encodings.string io.encodings.utf8 io.streams.byte-array
io.streams.string kernel math math.bitwise math.order namespaces
sequences strings ;
! Copyright (C) 2008 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.data arrays assocs byte-arrays
-byte-vectors combinators combinators.short-circuit fry
-hashtables hashtables.private hash-sets hints io.backend
-io.binary kernel locals math math.bitwise math.constants
-math.functions math.order math.ranges namespaces sequences
-sequences.private sets summary system typed vocabs ;
+byte-vectors combinators combinators.short-circuit endian fry
+hashtables hashtables.private hash-sets hints io.backend kernel
+locals math math.bitwise math.constants math.functions
+math.order math.ranges namespaces sequences sequences.private
+sets summary system typed vocabs ;
QUALIFIED-WITH: alien.c-types c
QUALIFIED-WITH: sets sets
IN: random
! See http://factorcode.org/license.txt for BSD license.
!
USING: accessors arrays assocs byte-arrays classes classes.tuple
-combinators hashtables hashtables.identity io io.binary
+combinators endian hashtables hashtables.identity io
io.encodings.binary io.encodings.string io.encodings.utf8
io.streams.byte-array kernel locals math namespaces prettyprint
quotations sequences sequences.private strings vocabs words ;
! Copyright (C) 2008 Doug Coleman, John Benediktsson.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.data alien.strings alien.syntax
-arrays assocs byte-arrays core-foundation io.binary
+arrays assocs byte-arrays core-foundation endian
io.encodings.utf8 kernel libc sequences specialized-arrays
splitting system system-info unix.users ;
SPECIALIZED-ARRAY: int
! Copyright (C) 2008 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: byte-arrays calendar checksums checksums.md5
-checksums.sha io.binary kernel math math.parser math.ranges
+checksums.sha endian kernel math math.parser math.ranges
random sequences strings system unicode ;
IN: uuid
! Copyright (C) 2021 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data arrays
-classes.struct destructors io.binary kernel literals sequences
+classes.struct destructors endian kernel literals sequences
strings windows windows.errors windows.handles windows.kernel32
windows.types ;
IN: windows.processes
le> head >string ;
: get-my-process-image-name ( -- string )
- GetCurrentProcess get-process-image-name ;
\ No newline at end of file
+ GetCurrentProcess get-process-image-name ;
! Copyright (C) 2006 Doug Coleman
! See http://factorcode.org/license.txt for BSD license.
-USING: checksums io.binary kernel math sequences
-sequences.private ;
+USING: checksums kernel math sequences sequences.private ;
IN: checksums.crc32
CONSTANT: crc32-polynomial 0xedb88320
: (crc32) ( crc ch -- crc )
dupd bitxor
- mask-byte crc32-table nth-unsafe
+ 0xff bitand crc32-table nth-unsafe
swap -8 shift bitxor ; inline
SINGLETON: crc32
: init-crc32 ( input checksum -- x y input )
drop [ 0xffffffff dup ] dip ; inline
+<PRIVATE
+: 4>be ( n -- byte-array ) ! duplicated from io.binary, but in core
+ { -24 -16 -8 0 } [ shift 0xff bitand ] with B{ } map-as ;
+PRIVATE>
+
: finish-crc32 ( x y -- bytes )
- bitxor 4 >be ; inline
+ bitxor 4>be ; inline
M: crc32 checksum-bytes
init-crc32
+++ /dev/null
-Slava Pestov
+++ /dev/null
-USING: help.markup help.syntax io math byte-arrays ;
-IN: io.binary
-
-ARTICLE: "stream-binary" "Working with binary data"
-"Stream words on binary streams only read and write byte arrays. Packed binary integers can be read and written by converting to and from sequences of bytes. Floating point numbers can be read and written by converting them into a their bitwise integer representation (" { $link "floats" } ")."
-$nl
-"There are two ways to order the bytes making up an integer; " { $emphasis "little endian" } " byte order outputs the least significant byte first, and the most significant byte last, whereas " { $emphasis "big endian" } " is the other way around."
-$nl
-"Consider the hexadecimal integer " { $snippet "0xcafebabe" } ". Little endian byte order yields the following sequence of bytes:"
-{ $table
- { "Byte:" "1" "2" "3" "4" }
- { "Value:" { $snippet "be" } { $snippet "ba" } { $snippet "fe" } { $snippet "ca" } }
-}
-"Compare this with big endian byte order:"
-{ $table
- { "Byte:" "1" "2" "3" "4" }
- { "Value:" { $snippet "ca" } { $snippet "fe" } { $snippet "ba" } { $snippet "be" } }
-}
-"Two words convert a sequence of bytes into an integer:"
-{ $subsections
- be>
- le>
-}
-"Two words convert an integer into a sequence of bytes:"
-{ $subsections
- >be
- >le
-}
-"Words for taking larger integers apart into smaller integers:"
-{ $subsections
- d>w/w
- w>h/h
- h>b/b
-} ;
-
-ABOUT: "stream-binary"
-
-HELP: be>
-{ $values { "seq" { $sequence "bytes" } } { "x" "a non-negative integer" } }
-{ $description "Converts a sequence of bytes in big endian order into an unsigned integer." } ;
-
-HELP: le>
-{ $values { "seq" { $sequence "bytes" } } { "x" "a non-negative integer" } }
-{ $description "Converts a sequence of bytes in little endian order into an unsigned integer." } ;
-
-HELP: nth-byte
-{ $values { "x" integer } { "n" "a non-negative integer" } { "b" "a byte" } }
-{ $description "Outputs the " { $snippet "n" } "th least significant byte of the sign-extended 2's complement representation of " { $snippet "x" } "." } ;
-
-HELP: >le
-{ $values { "x" integer } { "n" "a non-negative integer" } { "byte-array" byte-array } }
-{ $description "Converts an integer " { $snippet "x" } " into a string of " { $snippet "n" } " bytes in little endian order. Truncation will occur if the integer is not in the range " { $snippet "[-2^(8n),2^(8n))" } "." } ;
-
-HELP: >be
-{ $values { "x" integer } { "n" "a non-negative integer" } { "byte-array" byte-array } }
-{ $description "Converts an integer " { $snippet "x" } " into a string of " { $snippet "n" } " bytes in big endian order. Truncation will occur if the integer is not in the range " { $snippet "[-2^(8n),2^(8n))" } "." } ;
-
-HELP: mask-byte
-{ $values { "x" integer } { "y" "a non-negative integer" } }
-{ $description "Masks off the least significant 8 bits of an integer." } ;
-
-HELP: d>w/w
-{ $values { "d" "a 64-bit integer" } { "w1" "a 32-bit integer" } { "w2" "a 32-bit integer" } }
-{ $description "Outputs two integers, the least followed by the most significant 32 bits of the input." } ;
-
-HELP: w>h/h
-{ $values { "w" "a 32-bit integer" } { "h1" "a 16-bit integer" } { "h2" "a 16-bit integer" } }
-{ $description "Outputs two integers, the least followed by the most significant 16 bits of the input." } ;
-
-HELP: h>b/b
-{ $values { "h" "a 16-bit integer" } { "b1" "an 8-bit integer" } { "b2" "an 8-bit integer" } }
-{ $description "Outputs two integers, the least followed by the most significant 8 bits of the input." } ;
+++ /dev/null
-USING: io.binary tools.test classes math ;
-IN: io.binary.tests
-
-{ 0x03020100 } [ B{ 0 1 2 3 } le> ] unit-test
-{ 0x00010203 } [ B{ 0 1 2 3 } be> ] unit-test
-
-{ 0x332211 } [
- B{ 0x11 0x22 0x33 } le>
-] unit-test
-
-{ 0x04030201 } [ B{ 1 2 3 4 } signed-le> ] unit-test
-{ 0x01020304 } [ B{ 1 2 3 4 } signed-be> ] unit-test
-
-{ -12 } [ B{ 0xf4 0xff 0xff 0xff } signed-le> ] unit-test
-{ -12 } [ B{ 0xff 0xff 0xff 0xf4 } signed-be> ] unit-test
-
-{ 0x7a2c793b2ff08554 } [
- B{ 0x54 0x85 0xf0 0x2f 0x3b 0x79 0x2c 0x7a } le>
-] unit-test
-
-{ 0x988a259c3433f237 } [
- B{ 0x37 0xf2 0x33 0x34 0x9c 0x25 0x8a 0x98 } le>
-] unit-test
-
-{ B{ 0 0 4 0xd2 } } [ 1234 4 >be ] unit-test
-{ B{ 0 0 0 0 0 0 4 0xd2 } } [ 1234 8 >be ] unit-test
-{ B{ 0xd2 4 0 0 } } [ 1234 4 >le ] unit-test
-{ B{ 0xd2 4 0 0 0 0 0 0 } } [ 1234 8 >le ] unit-test
-
-{ 1234 } [ 1234 4 >be be> ] unit-test
-{ 1234 } [ 1234 4 >le le> ] unit-test
-
-{ fixnum } [ B{ 0 0 0 0 0 0 0 0 0 0 } be> class-of ] unit-test
-
-{ 0x56780000 0x12340000 } [ 0x1234000056780000 d>w/w ] unit-test
-{ 0x5678 0x1234 } [ 0x12345678 w>h/h ] unit-test
-{ 0x34 0x12 } [ 0x1234 h>b/b ] unit-test
+++ /dev/null
-! Copyright (C) 2003, 2007 Slava Pestov.
-! See http://factorcode.org/license.txt for BSD license.
-USING: kernel math sequences ;
-IN: io.binary
-
-: le> ( seq -- x ) 0 [ 8 * shift + ] reduce-index ;
-
-: be> ( seq -- x ) 0 [ [ 8 shift ] dip + ] reduce ;
-
-: mask-byte ( x -- y ) 0xff bitand ; inline
-
-: nth-byte ( x n -- b ) -8 * shift mask-byte ; inline
-
-<PRIVATE
-
-: map-bytes ( x seq -- byte-array )
- [ nth-byte ] with B{ } map-as ; inline
-
-PRIVATE>
-
-: >le ( x n -- byte-array ) <iota> map-bytes ;
-
-: >be ( x n -- byte-array ) <iota> <reversed> map-bytes ;
-
-: d>w/w ( d -- w1 w2 )
- [ 0xffffffff bitand ] [ -32 shift 0xffffffff bitand ] bi ;
-
-: w>h/h ( w -- h1 h2 )
- [ 0xffff bitand ] [ -16 shift 0xffff bitand ] bi ;
-
-: h>b/b ( h -- b1 b2 )
- [ mask-byte ] [ -8 shift mask-byte ] bi ;
-
-<PRIVATE
-
-: signed> ( x seq -- n )
- length 8 * 2dup 1 - bit? [ 2^ - ] [ drop ] if ; inline
-
-PRIVATE>
-
-: signed-le> ( bytes -- x ) [ le> ] [ signed> ] bi ;
-
-: signed-be> ( bytes -- x ) [ be> ] [ signed> ] bi ;
+++ /dev/null
-Utilities for reading and writing little and big endian data
! Copyright (C) 2006, 2009 Daniel Ehrenberg.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors byte-arrays combinators io io.binary
-io.encodings kernel math math.private namespaces sbufs
-sequences sequences.private splitting strings strings.private
-vectors ;
+USING: accessors byte-arrays combinators io io.encodings kernel
+math math.private namespaces sbufs sequences sequences.private
+splitting strings strings.private vectors ;
IN: io.encodings.utf16
SINGLETON: utf16be
[ B{ } 2sequence ] dip stream-write ; inline
! [ stream-write1 ] curry bi@ ; inline
+: split>b/b ( h -- b1 b2 ) ! duplicate from math.bitwise:h>b/b
+ [ 0xff bitand ] [ -8 shift 0xff bitand ] bi ;
+
: char>utf16be ( char stream -- )
over 0xFFFF > [
[ 0x10000 - ] dip
[ [ encode-first ] dip stream-write2 ]
[ [ encode-second ] dip stream-write2 ] 2bi
- ] [ [ h>b/b swap ] dip stream-write2 ] if ; inline
+ ] [ [ split>b/b swap ] dip stream-write2 ] if ; inline
M: utf16be encode-char
drop char>utf16be ;
[ 0x10000 - ] dip
[ [ encode-first swap ] dip stream-write2 ]
[ [ encode-second swap ] dip stream-write2 ] 2bi
- ] [ [ h>b/b ] dip stream-write2 ] if ; inline
+ ] [ [ split>b/b ] dip stream-write2 ] if ; inline
M: utf16le encode-char
drop char>utf16le ;
! See http://factorcode.org/license.txt for BSD license.
USING: arrays asn1.ldap assocs byte-arrays combinators
-continuations io io.binary io.streams.string kernel math
+continuations endian io io.streams.string kernel math
math.parser namespaces make pack strings sequences accessors ;
IN: asn1
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data audio
audio.chunked-file classes.struct combinators
-combinators.short-circuit endian io io.binary
-io.encodings.binary io.files kernel locals math sequences
-audio.loader ;
+combinators.short-circuit endian io io.encodings.binary
+io.files kernel locals math sequences audio.loader ;
IN: audio.aiff
CONSTANT: FORM-MAGIC "FORM"
! Copyright (C) 2009 Joe Groff.
! See http://factorcode.org/license.txt for BSD license.
USING: alien.c-types alien.syntax audio combinators endian
-combinators.short-circuit io io.binary io.encodings.binary
+combinators.short-circuit endian io io.encodings.binary
io.files io.streams.byte-array kernel locals math
sequences alien alien.data classes.struct accessors
audio.chunked-file audio.loader ;
-USING: base24 grouping io.binary kernel math.parser sequences
+USING: base24 endian grouping kernel math.parser sequences
tools.test ;
IN: base24.tests
! Copyright (C) 2020 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: ascii assocs base64.private byte-arrays grouping
-io.binary kernel kernel.private literals math sequences ;
+USING: ascii assocs base64.private byte-arrays endian grouping
+kernel kernel.private literals math sequences ;
IN: base24
! Copyright (C) 2019 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: base64.private byte-arrays combinators fry io io.binary
+USING: base64.private byte-arrays combinators endian fry io
io.encodings.binary io.streams.byte-array kernel kernel.private
literals math namespaces sequences ;
IN: base32
! See http://factorcode.org/license.txt for BSD license.
USING: base64.private byte-arrays checksums checksums.sha
-io.binary kernel kernel.private literals math math.functions
+endian kernel kernel.private literals math math.functions
sequences ;
IN: base36
! See http://factorcode.org/license.txt for BSD license.
USING: base64.private byte-arrays checksums checksums.sha
-io.binary kernel kernel.private literals math sequences ;
+endian kernel kernel.private literals math sequences ;
IN: base58
! See http://factorcode.org/license.txt for BSD license.
USING: base64.private byte-arrays checksums checksums.sha
-io.binary kernel kernel.private literals math sequences ;
+endian kernel kernel.private literals math sequences ;
IN: base62
! Copyright (C) 2013 John Benediktsson.
! See http://factorcode.org/license.txt for BSD license.
-USING: base64.private byte-arrays combinators io io.binary
+USING: base64.private byte-arrays combinators endian io
io.encodings.binary io.streams.byte-array kernel kernel.private
literals math namespaces sequences ;
IN: base85
-USING: cuckoo-filters fry io.binary kernel math sequences ;
+USING: cuckoo-filters endian fry kernel math sequences ;
IN: benchmark.cuckoo-filters
: insert-data ( cuckoo-filter -- cuckoo-filter )
! Copyright (C) 2011 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: accessors destructors fry io.binary io.sockets kernel
+USING: accessors destructors endian fry io.sockets kernel
sequences ;
IN: benchmark.udp-echo0
! Copyright (C) 2020 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: accessors arrays assocs bencode byte-arrays byte-vectors
-calendar checksums checksums.sha combinators destructors fry
-grouping http.client io io.binary io.encodings.binary io.files
+calendar checksums checksums.sha combinators destructors endian
+fry grouping http.client io io.encodings.binary io.files
io.pathnames io.sockets io.streams.byte-array io.streams.duplex
kernel literals locals make math math.bitwise math.functions
math.order math.parser math.ranges multiline namespaces
! Copyright (C) 2010 Sascha Matzke.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors assocs bson.constants byte-arrays calendar
-combinators combinators.short-circuit io io.binary io.encodings
+combinators combinators.short-circuit endian io io.encodings
io.encodings.binary io.encodings.utf8 io.files
io.streams.byte-array kernel locals math namespaces sequences
sequences.extras serialize strings typed vectors ;
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.accessors arrays assocs bson.constants
byte-arrays byte-vectors calendar combinators
-combinators.short-circuit dlists fry hashtables io io.binary
-io.encodings io.encodings.utf8 io.streams.byte-array kernel
+combinators.short-circuit dlists endian fry hashtables
+io io.encodings io.encodings.utf8 io.streams.byte-array kernel
linked-assocs literals math math.parser namespaces quotations
sequences serialize strings typed vectors words ;
IN: bson.writer
! See http://factorcode.org/license.txt for BSD license.
USING: accessors combinators combinators.short-circuit arrays
fry kernel layouts math namespaces sequences cpu.architecture
-math.bitwise math.order classes generalizations
-locals make alien.c-types io.binary grouping
+math.bitwise math.order classes endian generalizations
+locals make alien.c-types grouping
math.vectors.simd.intrinsics
compiler.cfg
compiler.cfg.registers
! See http://factorcode.org/license.txt for BSD license
USING: accessors alien.c-types alien.endian alien.strings assocs
-calendar calendar.parser classes.struct combinators fry io
-io.binary io.encodings.8-bit io.encodings.ascii
+calendar calendar.parser classes.struct combinators endian fry
+io io.encodings.8-bit io.encodings.ascii
io.encodings.binary io.encodings.string io.files
io.streams.byte-array kernel math math.parser namespaces
sequences splitting strings ;
! * REMOTE_ADDR
USING: accessors alien.enums alien.syntax assocs combinators
-combinators.smart formatting http http.server
-http.server.responses io io.binary io.directories
+combinators.smart endian formatting http http.server
+http.server.responses io io.directories
io.encodings.binary io.files io.servers io.sockets
io.streams.byte-array kernel locals math namespaces pack
prettyprint sequences sequences.deep strings threads
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs assocs.extras calendar
calendar.format checksums checksums.sha combinators
-combinators.smart compression.zlib constructors grouping io
-io.binary io.directories io.encodings.binary io.encodings.string
+combinators.smart compression.zlib constructors endian grouping
+io io.directories io.encodings.binary io.encodings.string
io.encodings.utf8 io.files io.files.info io.pathnames
io.streams.byte-array io.streams.peek kernel math math.bitwise
math.parser namespaces random sequences sequences.extras
! Copyright (C) 2007 Gavin Harrison
! See http://factorcode.org/license.txt for BSD license.
USING: kernel math sequences kernel.private namespaces arrays io
-io.files splitting grouping io.binary math.functions vectors
+io.files splitting grouping math.functions vectors endian
quotations combinators io.encodings.binary ;
IN: icfp.2006
! Copyright (C) 2007, 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data arrays byte-arrays
-combinators compression.run-length fry grouping images
-images.loader images.normalization io io.binary
+combinators compression.run-length endian fry grouping images
+images.loader images.normalization io
io.encodings.latin1 io.encodings.string io.streams.throwing
kernel math math.bitwise sequences specialized-arrays summary ;
QUALIFIED-WITH: bitstreams b
! Copyrigt (C) 2009 Doug Coleman, Keith Lazuka
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays combinators compression.lzw
-constructors destructors grouping images images.loader io
-io.binary io.buffers io.encodings.string io.encodings.utf8
+constructors destructors endian grouping images images.loader
+io io.buffers io.encodings.string io.encodings.utf8
kernel make math math.bitwise namespaces sequences ;
IN: images.gif
! Copyright (C) 2009 Marc Fauconneau.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays byte-arrays combinators
-compression.huffman fry grouping images images.loader
-images.processing io io.binary io.encodings.binary
+compression.huffman endian fry grouping images images.loader
+images.processing io io.encodings.binary
io.streams.byte-array io.streams.limited io.streams.throwing
kernel locals math math.bitwise math.blas.matrices
math.blas.vectors math.constants math.functions math.matrices
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs checksums checksums.crc32
-combinators compression.inflate fry grouping images
-images.loader io io.binary io.encodings.ascii
+combinators compression.inflate endian fry grouping images
+images.loader io io.encodings.ascii
io.encodings.binary io.encodings.latin1 io.encodings.string
io.streams.byte-array io.streams.throwing kernel locals math
math.bitwise math.functions sequences sorting ;
! Copyright (C) 2010 Erik Charlebois
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors images images.loader io io.binary kernel
+USING: accessors endian images images.loader io kernel
locals math sequences io.encodings.ascii io.encodings.string
calendar math.ranges math.parser colors arrays hashtables
ui.pixel-formats combinators continuations io.streams.throwing ;
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs byte-arrays combinators
combinators.short-circuit compression.lzw endian fry grouping
-images images.loader io io.binary io.encodings.ascii
+images images.loader io io.encodings.ascii
io.encodings.string io.encodings.utf8 io.streams.throwing kernel
math math.bitwise math.vectors pack sequences ;
IN: images.tiff
+++ /dev/null
-Doug Coleman
+++ /dev/null
-! Copyright (C) 2011 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: tools.test io.binary.fast ;
-
-{ 0x0102 } [ B{ 01 02 } 2be> ] unit-test
-{ 0x01020304 } [ B{ 01 02 03 04 } 4be> ] unit-test
-{ 0x0102030405060708 } [ B{ 01 02 03 04 05 06 07 08 } 8be> ] unit-test
-
-{ 0x0102 } [ B{ 02 01 } 2le> ] unit-test
-{ 0x01020304 } [ B{ 04 03 02 01 } 4le> ] unit-test
-{ 0x0102030405060708 } [ B{ 08 07 06 05 04 03 02 01 } 8le> ] unit-test
-
-{ 0x04030201 } [ B{ 1 2 3 4 } signed-le> ] unit-test
-{ 0x01020304 } [ B{ 1 2 3 4 } signed-be> ] unit-test
-
-{ -12 } [ B{ 0xf4 0xff 0xff 0xff } signed-le> ] unit-test
-{ -12 } [ B{ 0xff 0xff 0xff 0xf4 } signed-be> ] unit-test
+++ /dev/null
-! Copyright (C) 2011 Doug Coleman.
-! See http://factorcode.org/license.txt for BSD license.
-USING: alien.c-types alien.data byte-arrays combinators
-combinators.smart endian fry hints kernel locals macros math
-math.ranges sequences sequences.generalizations ;
-RENAME: be> io.binary => slow-be>
-RENAME: le> io.binary => slow-le>
-RENAME: signed-be> io.binary => slow-signed-be>
-RENAME: signed-le> io.binary => slow-signed-le>
-RENAME: >be io.binary => >slow-be
-RENAME: >le io.binary => >slow-le
-IN: io.binary.fast
-
-ERROR: bad-length bytes n ;
-
-: check-length ( bytes n -- bytes n )
- 2dup [ length ] dip > [ bad-length ] when ; inline
-
-<<
-: be-range ( n -- range )
- 1 - 8 * 0 -8 <range> ; inline
-
-: le-range ( n -- range )
- 1 - 8 * 0 swap 8 <range> ; inline
-
-: reassemble-bytes ( range -- quot )
- [ [ [ ] ] [ '[ _ shift ] ] if-zero ] map
- '[ [ _ spread ] [ bitor ] reduce-outputs ] ; inline
-
-MACRO: reassemble-be ( n -- quot ) be-range reassemble-bytes ;
-
-MACRO: reassemble-le ( n -- quot ) le-range reassemble-bytes ;
->>
-
-:: n-be> ( bytes n -- x )
- bytes n check-length drop n firstn-unsafe n reassemble-be ; inline
-
-:: n-le> ( bytes n -- x )
- bytes n check-length drop n firstn-unsafe n reassemble-le ; inline
-
-HINTS: n-be> { byte-array object } ;
-HINTS: n-le> { byte-array object } ;
-
-<PRIVATE
-: if-endian ( endian bytes-quot seq-quot -- )
- [
- compute-native-endianness =
- [ dup byte-array? ] [ f ] if
- ] 2dip if ; inline
-PRIVATE>
-
-: 2be> ( bytes -- x )
- big-endian [ uint16_t deref ] [ 2 n-be> ] if-endian ;
-
-: 4be> ( bytes -- x )
- big-endian [ uint32_t deref ] [ 4 n-be> ] if-endian ;
-
-: 8be> ( bytes -- x )
- big-endian [ uint64_t deref ] [ 8 n-be> ] if-endian ;
-
-: be> ( bytes -- x )
- dup length {
- { 2 [ 2be> ] }
- { 4 [ 4be> ] }
- { 8 [ 8be> ] }
- [ drop slow-be> ]
- } case ;
-
-: signed-be> ( bytes -- x )
- compute-native-endianness big-endian = [
- dup byte-array? [
- dup length {
- { 2 [ int16_t deref ] }
- { 4 [ int32_t deref ] }
- { 8 [ int64_t deref ] }
- [ drop slow-signed-be> ]
- } case
- ] [ slow-signed-be> ] if
- ] [ slow-signed-be> ] if ;
-
-: 2le> ( bytes -- x )
- little-endian [ uint16_t deref ] [ 2 n-le> ] if-endian ;
-
-: 4le> ( bytes -- x )
- little-endian [ uint32_t deref ] [ 4 n-le> ] if-endian ;
-
-: 8le> ( bytes -- x )
- little-endian [ uint64_t deref ] [ 8 n-le> ] if-endian ;
-
-: le> ( bytes -- x )
- dup length {
- { 2 [ 2le> ] }
- { 4 [ 4le> ] }
- { 8 [ 8le> ] }
- [ drop slow-le> ]
- } case ;
-
-: signed-le> ( bytes -- x )
- compute-native-endianness little-endian = [
- dup byte-array? [
- dup length {
- { 2 [ int16_t deref ] }
- { 4 [ int32_t deref ] }
- { 8 [ int64_t deref ] }
- [ drop slow-signed-le> ]
- } case
- ] [ slow-signed-le> ] if
- ] [ slow-signed-le> ] if ;
-
-: >le ( x n -- bytes )
- compute-native-endianness little-endian = [
- {
- { 2 [ int16_t <ref> ] }
- { 4 [ int32_t <ref> ] }
- { 8 [ int64_t <ref> ] }
- [ >slow-le ]
- } case
- ] [ >slow-le ] if ;
-
-: >be ( x n -- bytes )
- compute-native-endianness big-endian = [
- {
- { 2 [ int16_t <ref> ] }
- { 4 [ int32_t <ref> ] }
- { 8 [ int64_t <ref> ] }
- [ >slow-be ]
- } case
- ] [ >slow-be ] if ;
! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors timers bit-arrays calendar game.input io
-io.binary io.encodings.binary io.files kernel literals math
-namespaces system threads ;
+USING: accessors timers bit-arrays calendar endian game.input io
+io.encodings.binary io.files kernel literals math namespaces
+system threads ;
IN: key-logger
CONSTANT: frequency $[ 1/30 seconds ]
! Copyright (C) 2010 Erik Charlebois.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien alien.c-types alien.data alien.libraries
-alien.syntax classes.struct combinators endian io.binary
+alien.syntax classes.struct combinators endian
kernel locals math sequences specialized-arrays
system unix.time unix.types ;
FROM: alien.c-types => short ;
alien.syntax classes classes.struct combinators
combinators.short-circuit io.encodings.ascii io.encodings.string
kernel literals make math sequences specialized-arrays typed
-fry io.mmap formatting locals splitting io.binary arrays ;
+fry io.mmap formatting locals splitting endian arrays ;
FROM: alien.c-types => short ;
IN: macho
! Copyright (C) 2015 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: accessors assocs byte-arrays combinators fry io io.binary
+USING: accessors assocs byte-arrays combinators endian fry io
io.encodings.binary io.encodings.string io.encodings.utf8
io.files io.streams.byte-array io.streams.peek kernel literals
make math sequences sequences.generalizations ;
USING: accessors assocs bson.reader bson.writer byte-arrays
-byte-vectors combinators formatting fry io io.binary io.encodings.private
-io.encodings.binary io.encodings.string io.encodings.utf8 io.encodings.utf8.private io.files
-kernel locals math mongodb.msg namespaces sequences uuid bson.writer.private ;
+byte-vectors combinators formatting endian fry io
+io.encodings.private io.encodings.binary io.encodings.string
+io.encodings.utf8 io.encodings.utf8.private io.files kernel
+locals math mongodb.msg namespaces sequences uuid
+bson.writer.private ;
FROM: mongodb.connection => connection-buffer ;
FROM: alien => byte-length ;
! Copyright (C) 2019 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs combinators
-combinators.short-circuit continuations destructors fry io
-io.binary io.directories io.encodings.binary io.encodings.latin1
+combinators.short-circuit continuations destructors endian fry
+io io.directories io.encodings.binary io.encodings.latin1
io.encodings.string io.encodings.utf8 io.files io.files.info
io.sockets kernel math math.parser namespaces pack prettyprint
random sequences sequences.extras splitting strings ;
! Copyright (C) 2018 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: accessors byte-arrays classes combinators io
-io.binary.fast io.encodings.binary io.files
-io.streams.byte-array kernel locals math math.order
-math.statistics sequences sequences.extras sets ;
+USING: accessors byte-arrays classes combinators endian io
+io.encodings.binary io.files io.streams.byte-array kernel locals
+math math.order math.statistics sequences sequences.extras sets
IN: shapefiles
! Copyright (C) 2013 John Benediktsson.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs combinators formatting fry grouping hashtables
-io io.binary io.directories io.encodings.binary io.files
-io.files.types io.pathnames kernel math math.parser memoize pack
-sequences sequences.generalizations splitting strings system ;
+USING: accessors assocs combinators formatting endian fry
+grouping hashtables io io.directories io.encodings.binary
+io.files io.files.types io.pathnames kernel math math.parser
+memoize pack sequences sequences.generalizations splitting
+strings system ;
IN: terminfo
! Copyright (C) 2021 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: accessors colors combinators generalizations io io.binary
+USING: accessors colors combinators endian generalizations io
io.encodings.binary io.files io.streams.byte-array kernel math
math.bitwise namespaces sequences ;
! Copyright (C) 2018, 2020 Alexander Ilin.
! See http://factorcode.org/license.txt for BSD license.
-USING: base32 calendar checksums.hmac checksums.sha io.binary
+USING: base32 calendar checksums.hmac checksums.sha endian
kernel math math.bitwise math.parser namespaces sequences
strings unicode ;
IN: totp
! See http://factorcode.org/license.txt for BSD license
USING: accessors alien.c-types alien.data alien.endian arrays
-assocs calendar classes.struct combinators hashtables io
-io.binary io.encodings.binary io.files kernel locals math
-math.order sequences strings ;
+assocs calendar classes.struct combinators endian hashtables io
+io.encodings.binary io.files kernel locals math math.order
+sequences strings ;
IN: tzinfo
! Copyright (C) 2019 Alexander Ilin.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors io.binary kernel math namespaces sequences
+USING: accessors endian kernel math namespaces sequences
strings tools.test ulid ulid.private ;
IN: ulid.tests
! Copyright (C) 2018, 2019 Alexander Ilin.
! See http://factorcode.org/license.txt for BSD license.
-USING: ascii binary-search calendar io.binary kernel make math
+USING: ascii binary-search calendar endian kernel make math
math.bitwise math.order namespaces random sequences splitting
summary system tr ;
! Copyright (C) 2010 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: accessors alien.c-types alien.data classes.struct
-io.binary kernel literals locals make math math.bitwise
+endian kernel literals locals make math math.bitwise
sequences slots.syntax ui.backend.windows ui.gadgets.worlds
windows.errors windows.gdi32 windows.shcore windows.types
windows.user32 ;
: get-desktop-scale-factor ( -- n )
desktop-hmonitor 0 DEVICE_SCALE_FACTOR <ref>
- [ GetScaleFactorForMonitor win32-error=0/f ] keep le> ;
\ No newline at end of file
+ [ GetScaleFactorForMonitor win32-error=0/f ] keep le> ;
USING:
alien alien.data alien.libraries alien.syntax
- destructors formatting io.binary kernel libc locals
+ destructors endian formatting kernel libc locals
math math.bitwise
sequences windows.types
;