Note: This is taken from the Chicken Wiki, where a more recent version could be available.
packedobjects is a data encoding tool based on the telecommunications standard Packed Encoding Rules (PER). An abstract syntax language is used to define a protocol specification. packedobjects uses the Scheme programming language to represent the protocol specification within a symbolic expression (s-expression).
packedobjects is suitable for simple cross platform request/response protocols that require efficient encoding.
So far packedobjects has been run on the following platforms:
For a more detailed introduction refer to the following short paper.
John P. T. Moore <email@example.com>
svn checkout https://anonymous:@galinha.ucpel.tche.br/svn/chicken-eggs/packedobjects chicken-setup packedobjects.setup
(packedobjects <protocol> #!key <pdusize> <strsize>)
Creates a packedobject using the supplied protocol specification. Optional values for the PDU and string buffer sizes can be specified. They default to 5000 and 1000 respectively. Both the PDU buffer and string buffer are fixed in size. The string buffer must be large enough to handle any string used by the protocol. The PDU buffer must be manually freed.
(<packedobject> 'pack <values>)
Encodes a list of values and returns the number of bytes used.
Returns a list of values.
(<packedobject> 'read <fd> <size>)
Reads a number of bytes from a file descriptor into the PDU buffer.
(<packedobject> 'write <fd> <size>)
Writes a number of bytes from the PDU buffer to a file descriptor.
(<packedobject> 'read-message <fd>)
Reads a message from a file descriptor into the PDU buffer.
(<packedobject> 'write-message <fd> <size>)
Writes a message containing a number of bytes from the PDU buffer to a file descriptor.
A message consists of the encoded data plus a 2 byte header representing the length of the message. Therefore, the maximum message size is 2^16-1 bytes.
(<packedobject> 'dump-buffer <filename> <size>)
Dumps a number of bytes from the PDU buffer to a file.
Explicitly frees the PDU buffer. N.B. This call is optional as the memory will be automatically garbage collected.
The following data types are currently supported.
Constraints may be placed on all string types as well as integers. Restricting the size of strings and the range of integers can reduce the amount of bits encoded.
The following are valid string contraints:
The following are valid integer constraints:
Note, min and max denotes no lower bound and upper bound respectively, therefore () is equivalent to (size min max) or (range min max).
(require-extension packedobjects) (define bbcard '(bbcard sequence (name string (size 1 60)) (team string (size 1 60)) (age integer (range 1 100)) (position string (size 1 60)) (handedness enumerated (left-handed right-handed ambidextrous)) (batting-average sequence (mantissa integer ()) (base enumerated (2 10)) (exponent integer ())))) (define bbcard-values '(bbcard (name "Casey") (team "Mudville Nine") (age 32) (position "left field") (handedness ambidextrous) (batting-average (mantissa 250) (base 10) (exponent -3)))) (define po (packedobjects bbcard)) (print* "encoded in " (po 'pack bbcard-values) " bytes.\n") (print (po 'unpack)) (po 'free)
The following example retrieves random numbers from random.org.
The client talks to a server process which in turn obtains the numbers using HTTP. The data transferred between client and server is significantly more efficient, in terms of bits on the wire, than if the client talked directly to random.org using HTTP.
Copyright © 2006, John P. T. Moore
All rights reserved.