git clone https://depp.brause.cc/srfi-66.git
Table of Contents
- 1. SRFI-66: Octet Vectors
- 1.1. Abstract
- 1.2. Rationale
- 1.3. Specification
- 1.3.1. (u8vector? obj)
- 1.3.2. (make-u8vector k fill)
- 1.3.3. (u8vector octet …)
- 1.3.4. u8vector>list and list->u8vector
- 1.3.5. (u8vector-length u8vector)
- 1.3.6. (u8vector-ref u8vector k)
- 1.3.7. (u8vector-set! u8vector k octet)
- 1.3.8. (u8vector=? u8vector-1 u8vector-2)
- 1.3.9. (u8vector-compare u8vector-1 u8vector-2)
- 1.3.10. (u8vector-copy! source source-start target target-start n)
- 1.3.11. (u8vector-copy u8vector)
- 1.4. References
- 1.5. Authors
- 1.6. Copyright
- 1.7. Version history
1. SRFI-66: Octet Vectors
This SRFI defines a set of procedures for creating, accessing, and manipulating uniform vectors of octets.
For more information see: SRFI-66: Octet Vectors
A number of applications deal with sequences of octets (often called bytes), most prominently interfaces to C and I/O. Vectors are typically too space-costly and too slow to work well in these circumstance. This justifies having a separate type for octet vectors.
This SRFI is related to SRFI 4 (Homogeneous numeric vector datatypes), which also provides vectors of octets, and uses names consistent with it. However, the extension described here does not require any extensions to the syntax of the underlying Scheme system, and provides a slightly richer set of primtives.
Scheme systems implementing both SRFI 4 and this SRFI should use the same type for u8vector and octet vectors as specified here.
Octet vectors are objects of a new type. This type may or may not be disjoint from the type of regular vectors. Its elements must be octets, that is, exact integers in the range [0,255].
As with vectors, the length of a octet vector is the number of elements it contains. This number is fixed. A valid index into a octet vector is an exact, non-negative integer. The first element of a octet vector has index 0, the last element has an index one less than the length of the vector.
1.3.1. (u8vector? obj)
Returns #t if obj is an octect vector, otherwise returns #f. Analogous to vector?.
1.3.2. (make-u8vector k fill)
Returns a newly allocated octet vector of k elements. Each element is initialized to fill. Fill must be an octet. Analogous to make-vector.
1.3.3. (u8vector octet …)
Returns a newly allocated octet vector whose elements contain the given arguments, which must all be octets. Analogous to vector.
1.3.4. u8vector>list and list->u8vector
(u8vector->list u8vector) (list->u8vector octets)
- u8vector->list returns a newly allocated list of the elements of u8vector in the same order.Analogous to vector->list.
- List->u8vector returns a newly allocated octet vector whose elements are the elements of list octets, which must all be octets. Analogous to list->vector.
1.3.5. (u8vector-length u8vector)
Returns the number of elements in u8vector as an exact integer. Analogous to vector-length.
1.3.6. (u8vector-ref u8vector k)
k must be a valid index of u8vector. u8vector-ref returns the contents of element k of u8vector. Analogous to vector-ref.
1.3.7. (u8vector-set! u8vector k octet)
k must be a valid index of u8vector. u8vector-set! stores octet in element k of u8vector. The number of return values and the return values are unspecified. However, the number of return values is such that it is accepted by a continuation created by begin. Analogous to vector-set!.
1.3.8. (u8vector=? u8vector-1 u8vector-2)
Returns #t if u8vector-1 and u8vector-2 are equal—that is, if they have the same length and equal elements at all valid indices.
1.3.9. (u8vector-compare u8vector-1 u8vector-2)
Compares u8vector-1 and u8vector-2 and returns a value consistent with the vector ordering specified in SRFI 67, i.e. -1 if u8vector-1 is smaller than u8vector-2, 0 if they are equal, and 1 if u8vector-1 is greater than u8vector-2. Shorter vectors are always smaller than longer ones, and vectors of equal length are compared lexicographically.
1.3.10. (u8vector-copy! source source-start target target-start n)
Copies data from octet vector source to octet vector target. Source-start, target-start, and n must be non-negative exact integers that satisfy
- 0 <= source-start <= source-start + n <= (u8vector-length source)
- 0 <= target-start <= target-start + n <= (u8vector-length target)
This copies the octets from source at indices [source-start, source-start + n) to consecutive indices in target starting at target-index.
This must work even if the memory regions for the source and the target overlap, i.e., the octets at the target location after the copy must be equal to the octets at the source location before the copy.
The number of return values and the return values are unspecified. However, the number of return values is such that it is accepted by a continuation created by begin. Analogous to vector-ref.
1.3.11. (u8vector-copy u8vector)
Returns a newly allocated copy of octet vector u8vector.
1.4.1. SRFI 4 (Homogeneous numeric vector datatypes)
1.4.2. The "Byte Vectors" section of The Incomplete Scheme 48 Reference Manual available from this page.
1.5.1. Michael Sperber
1.5.2. Ported to Chicken Scheme 5 by Sergey Goldgaber
Copyright (C) Michael Sperber (2005). All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.