Commit | Line | Data |
---|---|---|
bce5cb56 | 1 | ;;;; bytevector.scm --- R6RS bytevector API -*- coding: utf-8 -*- |
1ee2c72e | 2 | |
bce5cb56 | 3 | ;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. |
1ee2c72e LC |
4 | ;;;; |
5 | ;;;; This library is free software; you can redistribute it and/or | |
6 | ;;;; modify it under the terms of the GNU Lesser General Public | |
7 | ;;;; License as published by the Free Software Foundation; either | |
83ba2d37 | 8 | ;;;; version 3 of the License, or (at your option) any later version. |
1ee2c72e LC |
9 | ;;;; |
10 | ;;;; This library is distributed in the hope that it will be useful, | |
11 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | ;;;; Lesser General Public License for more details. | |
14 | ;;;; | |
15 | ;;;; You should have received a copy of the GNU Lesser General Public | |
16 | ;;;; License along with this library; if not, write to the Free Software | |
17 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
18 | ||
bce5cb56 | 19 | ;;; Author: Ludovic Courtès <ludo@gnu.org> |
1ee2c72e LC |
20 | |
21 | ;;; Commentary: | |
22 | ;;; | |
23 | ;;; A "bytevector" is a raw bit string. This module provides procedures to | |
24 | ;;; manipulate bytevectors and interpret their contents in a number of ways: | |
25 | ;;; bytevector contents can be accessed as signed or unsigned integer of | |
26 | ;;; various sizes and endianness, as IEEE-754 floating point numbers, or as | |
27 | ;;; strings. It is a useful tool to decode binary data. | |
28 | ;;; | |
29 | ;;; Code: | |
30 | ||
31 | (define-module (rnrs bytevector) | |
32 | :export-syntax (endianness) | |
33 | :export (native-endianness bytevector? | |
34 | make-bytevector bytevector-length bytevector=? bytevector-fill! | |
782a82ee AW |
35 | bytevector-copy! bytevector-copy |
36 | uniform-array->bytevector | |
37 | bytevector-u8-ref bytevector-s8-ref | |
1ee2c72e LC |
38 | bytevector-u8-set! bytevector-s8-set! bytevector->u8-list |
39 | u8-list->bytevector | |
40 | bytevector-uint-ref bytevector-uint-set! | |
41 | bytevector-sint-ref bytevector-sint-set! | |
42 | bytevector->sint-list bytevector->uint-list | |
43 | uint-list->bytevector sint-list->bytevector | |
44 | ||
45 | bytevector-u16-ref bytevector-s16-ref | |
46 | bytevector-u16-set! bytevector-s16-set! | |
47 | bytevector-u16-native-ref bytevector-s16-native-ref | |
48 | bytevector-u16-native-set! bytevector-s16-native-set! | |
49 | ||
50 | bytevector-u32-ref bytevector-s32-ref | |
51 | bytevector-u32-set! bytevector-s32-set! | |
52 | bytevector-u32-native-ref bytevector-s32-native-ref | |
53 | bytevector-u32-native-set! bytevector-s32-native-set! | |
54 | ||
55 | bytevector-u64-ref bytevector-s64-ref | |
56 | bytevector-u64-set! bytevector-s64-set! | |
57 | bytevector-u64-native-ref bytevector-s64-native-ref | |
58 | bytevector-u64-native-set! bytevector-s64-native-set! | |
59 | ||
60 | bytevector-ieee-single-ref | |
61 | bytevector-ieee-single-set! | |
62 | bytevector-ieee-single-native-ref | |
63 | bytevector-ieee-single-native-set! | |
64 | ||
65 | bytevector-ieee-double-ref | |
66 | bytevector-ieee-double-set! | |
67 | bytevector-ieee-double-native-ref | |
68 | bytevector-ieee-double-native-set! | |
69 | ||
70 | string->utf8 string->utf16 string->utf32 | |
71 | utf8->string utf16->string utf32->string)) | |
72 | ||
73 | ||
44602b08 AW |
74 | (load-extension (string-append "libguile-" (effective-version)) |
75 | "scm_init_bytevectors") | |
1ee2c72e LC |
76 | |
77 | (define-macro (endianness sym) | |
78 | (if (memq sym '(big little)) | |
79 | `(quote ,sym) | |
80 | (error "unsupported endianness" sym))) | |
81 | ||
1ee2c72e | 82 | ;;; bytevector.scm ends here |