All Manuals > LispWorks® User Guide and Reference Manual > 47 The SYSTEM Package

octet-ref

base-char-ref Accessors

Summary

Loads an octet from a simple vector and returns it as an integer or base-char.

Package

system

Signatures

octet-ref vector octet-index => int

setf (octet-ref vector octet-index) int => int

base-char-ref vector octet-index => char

setf (base-char-ref vector octet-index) char => char

Arguments
vector
A simple-base-string, a simple-bmp-string or a simple binary vector.
octet-index
A non-negative integer.
int
An integer in the inclusive range [0, 255].
char
Values
int
An integer in the inclusive range [0, 255].
char
Description

The functions octet-ref and base-char-ref load an octet (8-bits element) from the simple vector vector at offset octet-index, and return it as an integer or base-char.

vector must be either a string with element type base-char or bmp-char or a simple binary vector, which means a simple vector of element type (unsigned-byte n) or (signed-byte n) for n = 8, 16, 32. In 64-bit LispWorks, n = 64 is also supported. vector cannot be displaced, adjustable or have a fill pointer, and it cannot be a string with element type character.

octet-index must be an integer, which is used as the count of octets (rather than array elements) to compute the actual offsets.

octet-ref, base-char-ref and their setters are intended to allow efficient access to (unsigned-byte 8) vectors and simple-base-string in the same code. For these types of vector they match what aref and (setf aref) do except that they always take and return the same value/result type, while aref and (setf aref) take and return a value of a type which depends on the type of the vector. octet-ref (and base-char-ref) are also more efficient than aref.

octet-ref, base-char-ref and their setters also work on simple binary vectors with element length other than 8 bits, and the results are consistent between themselves. However their results for such vectors do not match aref, because they will load and set either part of an element or multiple elements. Also the results of octet-ref (and base-char-ref) and the result of aref can differ between different platforms due to endianness.

Notes

octet-ref, base-char-ref and their setters cannot be used on a simple-text-string.

See also

28.2 Optimized integer arithmetic and integer vector access


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:31:02