1 Generic Interface
(require (planet "packing.ss" ("murphy" "packed-io.plt" 1 0))) |
This module provides the basic structure definitions, combinators
and frontend functions for packings.
1.1 Packing Structure
(struct packing (reader writer contract)) |
reader : (-> input-port? any/c) |
writer : (-> any/c output-port? any) |
contract : contract? |
A structure representing a packing. New packing combinators may want
to access the elements of the structure directly, client programs
should usually make use of the read-packed,
unpack, write-packed or pack procedures.
(with-eof-value/p eof-value packing) → packing? |
eof-value : (packing-contract packing) |
packing : packing? |
Creates a wrapped packing that replaces the end of input with the given
eof-value, which should obey the same contract as the values
regularly handled by the underlying packing.
Creates a wrapped packing that applies the given unwrapper
and wrapper procedures to values unpacked and packed using
the underlying packing.
The values produced and consumed by this packing obey the given wrapped-contract.
1.2 Packed I/O
(read-packed packing [in]) → (packing-contract packing) |
packing : packing? |
in : input-port? = (current-input-port) |
Reads a value from the input port in using the given
packing. The result is checked against the packing’s
contract.
Returns either an unpacked value or eof at the end of input.
(write-packed packing v [out]) → any |
packing : packing? |
v : (packing-contract packing) |
out : output-port? = (current-output-port) |
Writes the value v to the output port out using
the given packing. The input value is checked against the
packing’s contract.
1.3 Packed Byte Strings
Unpacks a value from the byte string b using the given
packing. The result is checked against the packing’s
contract.
Returns the unpacked value. A contract error is signalled if the end of the input buffer is reached before the packed value has been read completely.
Packs the value v into a byte string using the given
packing. The input value is checked against the packing’s
contract.
Returns a byte string containing the packed data.