Next: , Previous: , Up: stdlib bytevector   [Index]


5.2.2 General operations

Syntax: endianness ?endianness-symbol

The name of ?endianness-symbol must be a symbol describing an endianness. An implementation must support at least the symbols big and little, but may support other endianness symbols.

(endianness ?endianness-symbol) evaluates to the symbol named ?endianness-symbol. Whenever one of the procedures operating on bytevectors accepts an endianness as an argument, that argument must be one of these symbols. It is a syntax violation for ?endianness-symbol to be anything other than an endianness symbol supported by the implementation.

NOTE Implementors should use widely accepted designations for endianness symbols other than big and little.

NOTE Only the name of ?endianness-symbol is significant.

Procedure: native-endianness

Return the endianness symbol associated implementation’s preferred endianness (usually that of the underlying machine architecture). This may be any ?endianness-symbol, including a symbol other than big and little.

Procedure: bytevector? obj

Return #t if obj is a bytevector, #f otherwise.

Procedure: make-bytevector k
Procedure: make-bytevector k fill

Return a newly allocated bytevector of k bytes. If the fill argument is missing, the initial contents of the returned bytevector are unspecified. If the fill argument is present, it must be an exact integer object in the interval (-128, … 255) that specifies the initial value for the bytes of the bytevector: If fill is positive, it is interpreted as an octet; if it is negative, it is interpreted as a byte.

Procedure: bytevector-length bytevector

Return, as an exact integer object, the number of bytes in bytevector.

Procedure: bytevector=? bytevector1 bytevector2

Return #t if bytevector1 and bytevector2 are equal; that is, if they have the same length and equal bytes at all valid indices. It returns #f otherwise.

Procedure: bytevector-fill! bytevector fill

The fill argument is as in the description of the make-bytevector procedure. The bytevector-fill! procedure stores fill in every element of bytevector and returns unspecified values. Analogous to vector-fill!.

Procedure: bytevector-copy! source source-start target target-start k

source and target must be bytevectors. source-start, target-start, and k must be non–negative exact integer objects that satisfy:

0 <= source-start <= source-start + k <= l_source
0 <= target-start <= target-start + k <= l_target

where l_source is the length of source and l_target is the length of target.

The bytevector-copy! procedure copies the bytes from source at indices:

source-start, …, source-start + k - 1

to consecutive indices in target starting at target-start.

This must work even if the memory regions for the source and the target overlap, i.e., the bytes at the target location after the copy must be equal to the bytes at the source location before the copy.

Return unspecified values.

(let ((b (u8-list->bytevector '(1 2 3 4 5 6 7 8))))
  (bytevector-copy! b 0 b 3 4)
  (bytevector->u8-list b))
⇒ (1 2 3 1 2 3 4 8)
Procedure: bytevector-copy bytevector

Return a newly allocated copy of bytevector.


Next: , Previous: , Up: stdlib bytevector   [Index]