bytevectors.scm 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. bytevector-u8-ref bytevector-s8-ref
  34. bytevector-u8-set! bytevector-s8-set! bytevector->u8-list
  35. u8-list->bytevector
  36. bytevector-uint-ref bytevector-uint-set!
  37. bytevector-sint-ref bytevector-sint-set!
  38. bytevector->sint-list bytevector->uint-list
  39. uint-list->bytevector sint-list->bytevector
  40. bytevector-u16-ref bytevector-s16-ref
  41. bytevector-u16-set! bytevector-s16-set!
  42. bytevector-u16-native-ref bytevector-s16-native-ref
  43. bytevector-u16-native-set! bytevector-s16-native-set!
  44. bytevector-u32-ref bytevector-s32-ref
  45. bytevector-u32-set! bytevector-s32-set!
  46. bytevector-u32-native-ref bytevector-s32-native-ref
  47. bytevector-u32-native-set! bytevector-s32-native-set!
  48. bytevector-u64-ref bytevector-s64-ref
  49. bytevector-u64-set! bytevector-s64-set!
  50. bytevector-u64-native-ref bytevector-s64-native-ref
  51. bytevector-u64-native-set! bytevector-s64-native-set!
  52. bytevector-ieee-single-ref
  53. bytevector-ieee-single-set!
  54. bytevector-ieee-single-native-ref
  55. bytevector-ieee-single-native-set!
  56. bytevector-ieee-double-ref
  57. bytevector-ieee-double-set!
  58. bytevector-ieee-double-native-ref
  59. bytevector-ieee-double-native-set!
  60. string->utf8 string->utf16 string->utf32
  61. utf8->string utf16->string utf32->string))
  62. (load-extension (string-append "libguile-" (effective-version))
  63. "scm_init_bytevectors")
  64. (define-macro (endianness sym)
  65. (if (memq sym '(big little))
  66. `(quote ,sym)
  67. (error "unsupported endianness" sym)))
  68. ;;; bytevector.scm ends here