Protocol
=========

All messages start with a null byte. Everything else is interpreted as text and outputted verbatim to the output.

The first four bytes of each message (following the null byte) contain the total length of the
message, encoded as a number.

Entries are encoded as follows:
First byte  	    Meaning
0x00  		    nil.
0x01  		    cons. read two entries.
0x02		    number. read 4 bytes in network order
0x03		    string. read 4 bytes size and then n bytes in utf-8
0x04		    symbol. new symbol, read 4 bytes for its id, then a string.
0x05		    symbol. read 4 bytes, look up in the hash table.

Note: symbols are stored in a hash table for the server and the client. The server starts at high
id:s while the client starts allocating symbols at low id:s. Note that the server and the client
might accidentally allocate different id:s for the same symbol. This is not a problem.

Messages
=========

Messages are sent as a list of at least one element, where the first element is a symbol describing
the type of the message. Any remaining parameters depend on the message type that was sent.

Messages sent from a client to the server:

Message	                      Description
(quit)	 	 	      Asks the Storm process to quit.
(supported type)	      See if the file type 'type' is supported.
(open id path content <pos>)  Open a new file from 'path', hereby referred to as 'id' containing 'content'.
                              This is considered edit #0. If <pos> is included, it indicates the current position
			      of the cursor, the same as indicated by 'point' below.
(close id)    		      Close a previously opened file.
(edit file id from to text)   The file 'file' has been changed. This is edit number 'id'. The text between
                              'from' and 'to' is replaced by 'text'.
(point file pos)              Tell Storm that the point is now at 'pos'.
(indent file pos)	      Query the indentation of 'file' at position 'pos'.
(error file) 		      Find and report any parse errors in 'file' (in textual form).
(test ...)		      Messages used for testing the protocol. See below.
(chunk-size n <timeout>)      Set the size of chunks (in characters) sent to the client at once. 0 disables
	    		      sending coloring information unless eplicitly queried by the 'color' message.
			      An optional 'timeout' value explicitly sets the idle timeout.
(debug id mode)		      Output the internal representation of file 'id'. Used when debugging.
(color id)    	      	      Send coloring information for 'file' once more.


Messages sent from the server to a client:
(supported type result)	      Reports that 'type' is or is not supported, depending on 'result'
(color file id start colors)  Color 'file' using information from edit #'id'. Start at character 'start'
                              and color the next '(nth 0 colors)' using '(nth 1 colors)' and so on. Note:
			      'colors' is inlined in the list.
(indent file value)	      Returns the indentation for a previous 'indent' query. 'value' is either
                              'level n, indication indentation depth 'n', or 'as n, which indicates
			      that the line should be indented in the same level as the line at position 'n'.
(test ...)		      Messages used for testing the protocol. See below.


Colors
=======

Colore are sent as symbols, nil erases any coloring present.

comment
delimiter
string
constant
keyword
fn-name
var-name
type-name


Tests
======

To test the implementation of the protocol (ie. the low-level layer), there is a class of messages
for testing. These all start with (test ...). Due to the architecture, tests are driven by the
client.

These are the messages the server understands:

Message                    Description
(test start)		   Clears any test state.
(test stop)		   Sends any pending messages.
(test sum ...)		   Stores a sum of all entries following 'recv'. This makes (test stop)
                	   send (test sum <sum>).
(test send n msg between)  Send 'n' copies of 'msg', adding the string 'between' between each instance.
