You are looking at historical revision 16481 of this page. It may differ significantly from its current revision.
blob-record defines a macro to perform conversion between Scheme records and their representation as byte-blob|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:
- <type name> is bound to a representation of the record type itself.
- <constructor name> is bound to a procedure that takes as many arguments as there are <field spec> elements and returns a new <type name> record.
- <predicate name> is a predicate that returns #T when given a value returned by <constructor name> and #F for everything else.
- <size name> is the name of a variable that contains the total size of the record blob representation in bytes.
- Each <field spec> must provide the size of bytes for the byte blob representation of that field.
- Each <field spec> must also provide the names of procedures that can convert the field value to and from byte blobs.
- Each <accessor name> is a procedure that takes a record of type <type name> and returns the current value of the corresponding field. It is an error to pass an accessor a value which is not a record of the appropriate type.
(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))
- 1.0 Initial release
Copyright 2009 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 Lesser 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/>.