bytevectors.scm 3.3 KB

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