Merge commit '495cea0c931de23f074892b3f32808e676712a18'
[bpt/guile.git] / module / rnrs / bytevectors.scm
1 ;;;; bytevectors.scm --- R6RS bytevector API -*- coding: utf-8 -*-
2
3 ;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.
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
8 ;;;; version 3 of the License, or (at your option) any later version.
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
19 ;;; Author: Ludovic Courtès <ludo@gnu.org>
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 bytevectors)
32 #:version (6)
33 #:export-syntax (endianness)
34 #:export (native-endianness bytevector?
35 make-bytevector bytevector-length bytevector=? bytevector-fill!
36 bytevector-copy! bytevector-copy
37 uniform-array->bytevector
38 bytevector-u8-ref bytevector-s8-ref
39 bytevector-u8-set! bytevector-s8-set! bytevector->u8-list
40 u8-list->bytevector
41 bytevector-uint-ref bytevector-uint-set!
42 bytevector-sint-ref bytevector-sint-set!
43 bytevector->sint-list bytevector->uint-list
44 uint-list->bytevector sint-list->bytevector
45
46 bytevector-u16-ref bytevector-s16-ref
47 bytevector-u16-set! bytevector-s16-set!
48 bytevector-u16-native-ref bytevector-s16-native-ref
49 bytevector-u16-native-set! bytevector-s16-native-set!
50
51 bytevector-u32-ref bytevector-s32-ref
52 bytevector-u32-set! bytevector-s32-set!
53 bytevector-u32-native-ref bytevector-s32-native-ref
54 bytevector-u32-native-set! bytevector-s32-native-set!
55
56 bytevector-u64-ref bytevector-s64-ref
57 bytevector-u64-set! bytevector-s64-set!
58 bytevector-u64-native-ref bytevector-s64-native-ref
59 bytevector-u64-native-set! bytevector-s64-native-set!
60
61 bytevector-ieee-single-ref
62 bytevector-ieee-single-set!
63 bytevector-ieee-single-native-ref
64 bytevector-ieee-single-native-set!
65
66 bytevector-ieee-double-ref
67 bytevector-ieee-double-set!
68 bytevector-ieee-double-native-ref
69 bytevector-ieee-double-native-set!
70
71 string->utf8 string->utf16 string->utf32
72 utf8->string utf16->string utf32->string))
73
74
75 (load-extension (string-append "libguile-" (effective-version))
76 "scm_init_bytevectors")
77
78 (define-macro (endianness sym)
79 (if (memq sym '(big little))
80 `(quote ,sym)
81 (error "unsupported endianness" sym)))
82
83 ;;; bytevector.scm ends here