Introduction

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).

Version

Building from subversion repository

Usage

(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.

(<packedobject> 'unpack)

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.

(<packedobject> 'free)

Frees the PDU buffer.

Data types with examples

The following data types are currently supported.

string

protocol

(foobar string (size 1 10))

values

(foobar "foobar")

description

7 bit string limited to 10 characters in length.

octet-string

protocol

(foobar octet-string ())

values

(foobar "foobar")

description

8 bit string with no length restriction.

bit-string

protocol

(foobar bit-string (size 8))

values

(foobar "10101010")

description

Bitstring fixed in length.

hex-string

protocol

(foobar hex-string (size 1 max))

values

(foobar "afafaf")

description

String of hexadecimal characters with no length restriction.

integer

protocol

(foobar integer (range 1 10))

values

(foobar 5)

description

Integer with a minimum allowed value of 1 and maximum allowed value of 10.

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.