Janet 1.38.0-73334f3 Documentation
(Other Versions:
1.37.1
1.36.0
1.35.0
1.34.0
1.31.0
1.29.1
1.28.0
1.27.0
1.26.0
1.25.1
1.24.0
1.23.0
1.22.0
1.21.0
1.20.0
1.19.0
1.18.1
1.17.1
1.16.1
1.15.0
1.13.1
1.12.2
1.11.1
1.10.1
1.9.1
1.8.1
1.7.0
1.6.0
1.5.1
1.5.0
1.4.0
1.3.1
)
Buffer Module
Index
buffer/bit buffer/bit-clear buffer/bit-set buffer/bit-toggle buffer/blit buffer/clear buffer/fill buffer/format buffer/format-at buffer/from-bytes buffer/new buffer/new-filled buffer/popn buffer/push buffer/push-at buffer/push-byte buffer/push-float32 buffer/push-float64 buffer/push-string buffer/push-uint16 buffer/push-uint32 buffer/push-uint64 buffer/push-word buffer/slice buffer/trim
(buffer/bit buffer index)
Gets the bit at the given bit-index. Returns true if the bit is set, false if not.
(buffer/bit-clear buffer index)
Clears the bit at the given bit-index. Returns the buffer.
(buffer/bit-set buffer index)
Sets the bit at the given bit-index. Returns the buffer.
(buffer/bit-toggle buffer index)
Toggles the bit at the given bit index in buffer. Returns the buffer.
(buffer/blit dest src &opt dest-start src-start src-end)
Insert the contents of src
into dest
. Can optionally take indices that indicate which part of src
to copy
into which part of dest
. Indices can be negative in order to index from the end of src
or dest
. Returns
dest
.
(buffer/clear buffer)
Sets the size of a buffer to 0 and empties it. The buffer retains its memory so it can be efficiently refilled. Returns the modified buffer.
(buffer/fill buffer &opt byte)
Fill up a buffer with bytes, defaulting to 0s. Does not change the buffer's length. Returns the modified buffer.
(buffer/format buffer format & args)
Snprintf like functionality for printing values into a buffer. Returns the modified buffer.
(buffer/format-at buffer at format & args)
Snprintf like functionality for printing values into a buffer. Returns the modified buffer.
(buffer/from-bytes & byte-vals)
Creates a buffer from integer parameters with byte values. All integers will be coerced to the range of 1 byte 0-255.
(buffer/new capacity)
Creates a new, empty buffer with enough backing memory for capacity
bytes. Returns a new buffer of length 0.
(buffer/new-filled count &opt byte)
Creates a new buffer of length count
filled with byte
. By default, byte
is 0. Returns the new buffer.
(buffer/popn buffer n)
Removes the last n
bytes from the buffer. Returns the modified buffer.
(buffer/push buffer & xs)
Push both individual bytes and byte sequences to a buffer. For each x in xs, push the byte if x is an integer,
otherwise push the bytesequence to the buffer. Thus, this function behaves like both buffer/push-string
and
buffer/push-byte
. Returns the modified buffer. Will throw an error if the buffer overflows.
(buffer/push-at buffer index & xs)
Same as buffer/push, but copies the new data into the buffer at index index
.
(buffer/push-byte buffer & xs)
Append bytes to a buffer. Will expand the buffer as necessary. Returns the modified buffer. Will throw an error if the buffer overflows.
(buffer/push-float32 buffer order data)
Push the underlying bytes of a 32 bit float data onto the end of the buffer. Returns the modified buffer.
(buffer/push-float64 buffer order data)
Push the underlying bytes of a 64 bit float data onto the end of the buffer. Returns the modified buffer.
(buffer/push-string buffer & xs)
Push byte sequences onto the end of a buffer. Will accept any of strings, keywords, symbols, and buffers. Returns the modified buffer. Will throw an error if the buffer overflows.
(buffer/push-uint16 buffer order data)
Push a 16 bit unsigned integer data onto the end of the buffer. Returns the modified buffer.
(buffer/push-uint32 buffer order data)
Push a 32 bit unsigned integer data onto the end of the buffer. Returns the modified buffer.
(buffer/push-uint64 buffer order data)
Push a 64 bit unsigned integer data onto the end of the buffer. Returns the modified buffer.
(buffer/push-word buffer & xs)
Append machine words to a buffer. The 4 bytes of the integer are appended in twos complement, little endian order, unsigned for all x. Returns the modified buffer. Will throw an error if the buffer overflows.
(buffer/slice bytes &opt start end)
Takes a slice of a byte sequence from start
to end
. The range is half open, [start, end). Indexes can also
be negative, indicating indexing from the end of the end of the array. By default, start
is 0 and end
is
the length of the buffer. Returns a new buffer.
(buffer/trim buffer)
Set the backing capacity of the buffer to the current length of the buffer. Returns the modified buffer.