(util buffer) - Buffer utilities

Library (util buffer)

This library provides buffer utitlities. Currently, it only provides pre-allocated buffer and its procedures.

Pre-allocated buffer

Parent type of pre-allocated buffer. This library doesn't expose the record constructor for this type.

This type contains buffer and size fields.

Returns #t if given obj is a pre-allocated buffer. Otherwise #f.

Returns value of buffer field of given buffer.

The type of buffer field is implementation specific.

Returns value of size field of given buffer.

The returning value shall represents how much buffer of the given _buffer_is consumed.

Sets 0 to the size field of given buffer.

Conditions

Buffer overflow condition. This is raised when an operation tries to put data exceed the buffer size.

This condition have data field which contains overflowing data.

Returns #t if given obj is &pre-allocated-buffer-overflowcondition, otherwise #f.

Retrieves data field value of condition.

The condition must be a &pre-allocated-buffer-overflow condition.

Binary pre-allocated buffer

Binary pre-allocated buffer can be used when users don't want to allocate bytevector number of times. This buffer can be used like a bytevector.

Creates pre-allocated buffer with given bytevector bv.

The returning value is a subtype of <pre-allocated-buffer>.

Returns #t if given obj is binary pre-allocated buffer, otherwise #f.

Operations

Appending given integer or flonum to binary-buffer. Setting given values uses the following procedures, respectively:

bytevector-u8-set!``bytevector-u16-set!``bytevector-u32-set!``bytevector-u64-set!``bytevector-s8-set!``bytevector-s16-set!``bytevector-s32-set!``bytevector-s64-set!``bytevector-ieee-single-set!``bytevector-ieee-double-set!The endianness is passed to the above procedures if required.

This procedure also updates the size field of binary-buffer.

Appending given bytevector bv to binary-buffer.

Optional arguments start and count specifies from where of bv and how much bytes need to be put. By default, start is 0 and count is (- (bytevector-length _bv_) _start_).

This procedure also updates the size field of binary-buffer.

Setting given integer/flonum to binary-buffer. These procedures are anology of the following procedures, respectively:

bytevector-u8-set!``bytevector-s8-set!``bytevector-u16-set!``bytevector-u32-set!``bytevector-u64-set!``bytevector-s16-set!``bytevector-s32-set!``bytevector-s64-set!``bytevector-ieee-single-set!``bytevector-ieee-double-set!The endianness is passed to the above procedures if required.

This procedure updates the size field of binary-buffer if sum of given index and number of bytes set in the buffer exceeds the size of the buffer.

Sets the given bv to binary-buffer at position of index.

Optional arguments start and count specifies from where of bv and how much bytes need to be put. By default, start is 0 and count is (- (bytevector-length _bv_) _start_).

This procedure updates the size field of binary-buffer if sum of given index and number of bytes set in the buffer exceeds the size of the buffer.

All above operations may raises an &pre-allocated-buffer-overflow, when it tries to exceed the pre-allocated buffer.

Returns #t if binary-buffer can store count bytes.

If optional argument position is given, then the procedure check from the position.

Swaps the buffer of binary-buffer with _new-buf_and new-size.

Reads n bytes from given input-port and store it to binary-buffer.

If optional argument position is given, then the procedure stores from the position.

Returns newly allocated bytevector which contains range of 0 to size field value of buffer field.

Converts the given binary-buffer to binary output port.

If port operations try to exceed the pre-allocated buffer, then it raises &pre-allocated-buffer-overflow.