     
 : read-128-ber ( -- n )
     0 (read-128-ber) ;
+
+<PRIVATE
 
 CONSTANT: pack-table
     H{

: big-endian? ( -- ? )
    1 <int> *char zero? ;

: set-big-endian ( -- )
    big-endian? big-endian set ; inline

: >endian ( obj n -- str )
    big-endian get [ >be ] [ >le ] if ; inline

        { CHAR: D 8 }
    }

MACRO: pack ( seq str -- quot )
    [ pack-table at 1quotation '[ _ @ ] ] [ ] 2map-as concat
    '[ _ B{ } make ] ;

PRIVATE>
 
: pack-native ( seq str -- seq )
    [ set-big-endian pack ] with-scope ; inline

: pack-be ( seq str -- seq )
    [ big-endian on pack ] with-scope ; inline

: pack-le ( seq str -- seq )
    [ big-endian off pack ] with-scope ; inline

<PRIVATE

MACRO: unpack ( str -- quot )
    [ unpack-table at 1quotation '[ @ , ] ] { } map-as concat
    '[ [ _ { } make ] with-string-reader ] ;

PRIVATE>

: unpack-native ( seq str -- seq )
    [ set-big-endian unpack ] with-scope ; inline

: unpack-be ( seq str -- seq )
    [ big-endian on unpack ] with-scope ; inline

: unpack-le ( seq str -- seq )
    [ big-endian off unpack ] with-scope ; inline

: packed-length ( str -- n )
    [ packed-length-table at ] sigma ;
