### ----------------------------------------------------
### -- Numeric::Pack
### -- Licenses: Artistic-2.0
### -- Authors: Sam Gillespie
### -- File: README.md
### ----------------------------------------------------
### -- Chunk 3 of 3
r = { ... }

) returns Int

```



Unpack an unsigned 8 byte integer buffer. Exported via tag :ints.



### sub pack-int16



```perl6

sub pack-int16(

    Int(Cool) $int,

    ByteOrder :$byte-order = { ... }

) returns Buf

```



Pack an Int to a 2 byte integer buffer Exported via tag :ints. Be aware that the behaviour of Int values outside the range of a signed 16bit integer [���32,768 to 32,767] is undefined.



### sub unpack-int16



```perl6

sub unpack-int16(

    Buf $int-buf,

    ByteOrder :$byte-order = { ... }

) returns Int

```



Unpack a signed 2 byte integer buffer. Exported via tag :ints.



### sub pack-uint16



```perl6

sub pack-uint16(

    UInt(Cool) $int,

    ByteOrder :$byte-order = { ... }

) returns Buf

```



Pack an Int to a 2 byte unsigned integer buffer Exported via tag :ints. Be aware that the behaviour of Int values outside the range of an unsigned 16bit integer [0 to 65,535] is undefined.



### sub unpack-uint16



```perl6

sub unpack-uint16(

    Buf $int-buf,

    ByteOrder :$byte-order = { ... }

) returns Int

```



Unpack an unsigned 2 byte integer buffer. Exported via tag :ints.



### sub pack-int8



```perl6

sub pack-int8(

    Int(Cool) $int,

    ByteOrder :$byte-order = { ... }

) returns Buf

```



Pack an Int to a 1 byte integer buffer Exported via tag :ints. Be aware that the behaviour of Int values outside the range of a signed 8 bit integer [���128 to 127] is undefined.



### sub unpack-int8



```perl6

sub unpack-int8(

    Buf $int-buf,

    ByteOrder :$byte-order = { ... }

) returns Int

```



Unpack a signed 1 byte integer buffer. Exported via tag :ints.



### sub pack-uint8



```perl6

sub pack-uint8(

    UInt(Cool) $int,

    ByteOrder :$byte-order = { ... }

) returns Buf

```



Pack an Int to a 1 byte unsigned integer buffer Exported via tag :ints. Be aware that the behaviour of Int values outside the range of an unsigned 16bit integer [0 to 255] is undefined.



### sub unpack-uint8



```perl6

sub unpack-uint8(

    Buf $int-buf,

    ByteOrder :$byte-order = { ... }

) returns Int

```



Unpack an unsigned 1 byte integer buffer. Exported via tag :ints.



### sub pack-ber



```perl6

sub pack-ber(

    Int $val where { ... }

) returns Buf

```



Analogue to the perl pack 'w' option. Which is stated to be different to ANS.1 BER format, see: https://perldoc.perl.org/perlpacktut.html#Another-Portable-Binary-Encoding This encoding handles an unsigned integer value of an arbitrary size in the minimum number of bytes. Each byte has 7 bits available with the first bit signalling continuation or conclusion of the encoded value.



### sub unpack-ber



```perl6

sub unpack-ber(

    Buf $bytes

) returns UInt

```



Corresponding unpacker for pack-ber, the resulting Int will be 0 to an arbitrary limit. Decoding will always result in a value but an error in the encoding will not be reported. You can use collect-ber() to obtain a sub buffer for decoding from another buffer.



### sub collect-ber



```perl6

sub collect-ber(

    Buf $bytes,

    Int :$offset where { ... } = 0

) returns Buf

```



This utility returns a copy of the sub buffer containing a ber encoded integer from the given offset. The sub buffer can then be given to unpack ber to decode the buffer into an Int.




