chickadee » blob-record

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

blob-record

Description

blob-record defines a macro to perform conversion between Scheme records and their representation as byte blobs.

The syntax of a record-type definition is loosely based on SRFI-9:

<record type definition>
   -> (define-blob-record <type name>
        ( <predicate name> <constructor name> <size name> )
        ( <blob->record name> <record->blob name> )
        <field spec> ...)
<field spec> -> ( <field tag> <size in bytes> <accessor name> 
                  <field->blob name> <blob->field name> )
 
<field tag> -> <identifier>
 
<... name>  -> <identifier>

An instance of define-blob-record is equivalent to the following definitions:

Example

(use srfi-4 byte-blob blob-record test)

(define-blob-record testrec
  (testrec? make-testrec testrec-size)
  (blob->testrec testrec->blob)
  (x  8 testrec-x s16vector->byte-blob byte-blob->s16vector)
  (y  4 testrec-y string->byte-blob byte-blob->string)
  (z  12 testrec-z f32vector->byte-blob byte-blob->f32vector))

(define-record-printer (testrec x out)
  (fprintf out "#<testrec x=~A y=~A z=~A>"
 	   (testrec-x x)
 	   (testrec-y x)
	   (testrec-z x)))

(define a (make-testrec (s16vector 1 3 5 7) "blah" (f32vector 4.0 5.0 6.0)))

(blob->testrec (testrec->blob a))

Version History

License

 Copyright 2009-2011 Ivan Raikov and the Okinawa Institute of Science and Technology.
 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as
 published by the Free Software Foundation, either version 3 of the
 License, or (at your option) any later version.
 This program is distributed in the hope that it will be useful, but
 WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 General Public License for more details.
 A full copy of the GPL license can be found at
 <http://www.gnu.org/licenses/>.