Copyright (C) 2002  Internet Software Consortium.

Permission to use, copy, modify, and distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

$Id: wire-format.txt,v 1.3 2002/12/06 02:04:52 lidl Exp $

Wire format for messages.

The general format:

message = {
	VERSION
	HASH
}

VERSION = 0x536b616e;

For item types, the lower 4 bits describe the type of item, while the
upper 4 bits describe the length prefix used:

	ITEM_DATA = 0x01
	ITEM_HASH = 0x02
	ITEM_LIST = 0x03
	ITEM_NULL = 0x04

	LENGTH_32 = 0x00
	LENGTH_16 = 0x10
	LENGTH_8  = 0x20

An "item" is either a literal string of bytes, a NULL, a HASH, or a LIST.

NULL = ITEM_NULL

NULL values are encoded without a data length or any data.

HASH values are encoded with a type of ITEM_HASH, followed by a length of the
hash itself.  The one exception to this is the top level hash, which has no
item type or length encoded.

HASH = ITEM_HASH length *(tag-len-byte tag-name item-type item-len item)

LIST values are encoded with a type of ITEM_LIST, followed by a length of the
list.

LIST = ITEM_LIST length *(item-type item-len item)

For example, the following Perl structure would be encoded on the wire like
this, assuming all length bytes are 1 byte long:

$msg = {
  foo => "bar",
  baz => { abc => 123 },
  arr => [ "1", "a", [ "5", "t" ] ],
  test => "yes"
}

0x536b6e61			VERSION

				{
3 "foo" 0x21 3 "bar"			foo => "bar",
3 "baz"	0x22 9				baz => {
	3 "abc" 0x21 3 "123"				abc => 123,
						},
3 "arr" 0x23  12			arr => [
	0x21 1 "1"				 "1",
	0x21 1 "a"				 "a",
	0x23 6					[
		0x21 1 "5"				"5",
		0x21 1 "t"				"t"
						]
					],
4 "test" 0x21 3 "yes"			test => "yes",
				}


