let i = 0 ; since param receptive param bytes internal private export function create ( receptive , bytes ) { const header = new Uint8Array ( 11 + bytes . byteLength ) ; writeDate ( header , Date . now ( ) ) ; writeIncrement ( header , i ) ; writeReceptive ( header , receptive ) ; write32At ( header , bytes . byteLength , 7 ) ; header . set ( bytes , 11 ) ; i = i < 0xFFFF ? i + 1 : 0 ; return header ; } since param id param receptive param bytes internal private export function createFromID ( id , receptive , bytes ) { const header = new Uint8Array ( 11 + bytes . byteLength ) ; writeDate ( header , Number ( BigInt ( id ) >> 16n ) ) ; writeIncrement ( header , id & 0xFFFF ) ; writeReceptive ( header , receptive ) ; write32At ( header , bytes . byteLength , 7 ) ; header . set ( bytes , 11 ) ; return header ; } since param header internal private export function read ( header ) { return { id : readID ( header ) , receptive : Boolean ( header [ 6 ] ) , byteLength : read32At ( header , 7 ) } ; } since param header param date internal private export function writeDate ( header , date ) { write32At ( header , date % 0xFFFFFFFF , 0 ) ; } since param header param increment internal private export function writeIncrement ( header , increment ) { header [ 5 ] = increment & 0xFF ; increment >>= 8 ; header [ 4 ] = increment & 0xFF ; } since param buffer param value param offset internal private export function write32At ( buffer , value , offset ) { buffer [ offset + 3 ] = value ; value >>>= 8 ; buffer [ offset + 2 ] = value ; value >>>= 8 ; buffer [ offset + 1 ] = value ; value >>>= 8 ; buffer [ offset ] = value ; } since param header param receptive internal private export function writeReceptive ( header , receptive ) { header [ 6 ] = receptive ? 1 : 0 ; } since param header internal private export function readID ( header ) { return Number ( BigInt ( readDate ( header ) ) << 16n ) + readIncrement ( header ) ; } since param header internal private export function readDate ( header ) { return read32At ( header , 0 ) ; } since param header internal private export function readIncrement ( header ) { return ( header [ 4 ] << 0o10 ) + header [ 5 ] ; } since param buffer param offset internal private export function read32At ( buffer , offset ) { return ( buffer [ offset ++ ] * ( 2 ** 24 ) ) + ( buffer [ offset ++ ] * ( 2 ** 16 ) ) + ( buffer [ offset ++ ] * ( 2 ** 8 ) ) + buffer [ offset ++ ] ; }