~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/specifications/banana.html

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html  PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN'  'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'><html lang="en" xmlns="http://www.w3.org/1999/xhtml">
 
2
  <head>
 
3
<title>Twisted Documentation: Banana Protocol Specifications</title>
 
4
<link href="../howto/stylesheet.css" rel="stylesheet" type="text/css"/>
 
5
  </head>
 
6
 
 
7
  <body bgcolor="white">
 
8
    <h1 class="title">Banana Protocol Specifications</h1>
 
9
    <div class="toc"><ol><li><a href="#auto0">Introduction</a></li><li><a href="#auto1">Banana Encodings</a></li><li><a href="#auto2">Element Types</a></li><ul><li><a href="#auto3">Examples</a></li></ul><li><a href="#auto4">Profiles</a></li><ul><li><a href="#auto5">The &quot;none&quot; Profile</a></li><li><a href="#auto6">The &quot;pb&quot; Profile</a></li></ul><li><a href="#auto7">Protocol Handshake and Behaviour</a></li></ol></div>
 
10
    <div class="content">
 
11
    <span/>
 
12
 
 
13
    <h2>Introduction<a name="auto0"/></h2>
 
14
 
 
15
    <p>
 
16
      Banana is an efficient, extendable protocol for sending and receiving s-expressions.
 
17
      A s-expression in this context is a list composed of byte strings, integers, 
 
18
      large integers, floats and/or s-expressions.
 
19
    </p>
 
20
 
 
21
    <h2>Banana Encodings<a name="auto1"/></h2>
 
22
 
 
23
    <p>
 
24
      The banana protocol is a stream of data composed of elements. Each element has the
 
25
      following general structure - first, the length of element encoded in base-128, least signficant
 
26
      bit first. For example length 4674 will be sent as <code>0x42 0x24</code>. For certain element
 
27
      types the length will be omitted (e.g. float) or have a different meaning (it is the actual
 
28
      value of integer elements).
 
29
    </p>
 
30
 
 
31
    <p>
 
32
      Following the length is a delimiter byte, which tells us what kind of element this
 
33
      is. Depending on the element type, there will then follow the number of bytes specified
 
34
      in the length. The byte's high-bit will always be set, so that we can differentiate
 
35
      between it and the length (since the length bytes use 128-base, their high bit will
 
36
      never be set).
 
37
    </p>
 
38
 
 
39
    <h2>Element Types<a name="auto2"/></h2>
 
40
 
 
41
    <p>
 
42
      Given a series of bytes that gave us length N, these are the different delimiter bytes:
 
43
    </p>
 
44
 
 
45
    <dl>
 
46
      <dt>List -- 0x80</dt>
 
47
      
 
48
      <dd>The following bytes are a list of N elements.  Lists may be nested,
 
49
        and a child list counts as only one element to its parent (regardless
 
50
        of how many elements the child list contains). </dd>
 
51
 
 
52
      <dt>Integer -- 0x81</dt>
 
53
      <dd>The value of this element is the positive integer N. Following bytes are not part of this element. Integers can have values of 0 &lt;= N &lt;= 2147483647.</dd>
 
54
 
 
55
      <dt>String -- 0x82</dt>
 
56
      <dd>The following N bytes are a string element.</dd>
 
57
 
 
58
      <dt>Negative Integer -- 0x83</dt>
 
59
      <dd>The value of this element is the integer N * -1, i.e. -N. Following bytes are not part of this element. Negative integers can have values of 0 &gt;= -N &gt;= -2147483648.</dd>
 
60
 
 
61
      <dt>Float - 0x84</dt>
 
62
      <dd>The next 8 bytes are the float encoded in IEEE 754 floating-point <q>double format</q> bit layout.
 
63
        No length bytes should have been defined.
 
64
      </dd>
 
65
 
 
66
      <dt>Large Integer -- 0x85</dt>
 
67
      <dd>The value of this element is the positive large integer N. Following bytes are not part of this element. Large integers have no size limitation.</dd>
 
68
 
 
69
      <dt>Large Negative Integer -- 0x86</dt>
 
70
      <dd>The value of this element is the negative large integer -N. Following bytes are not part of this element. Large integers have no size limitation.</dd>
 
71
    </dl>
 
72
 
 
73
    <p>
 
74
      Large integers are intended for arbitary length integers. Regular integers types (positive and negative) are limited to 32-bit values.
 
75
    </p>
 
76
 
 
77
    <h3>Examples<a name="auto3"/></h3>
 
78
 
 
79
    <p>
 
80
      Here are some examples of elements and their encodings - the type bytes are marked in bold:
 
81
    </p>
 
82
 
 
83
    <dl>
 
84
      <dt><code>1</code></dt>
 
85
      <dd><code>0x01 <strong>0x81</strong></code></dd>
 
86
      <dt><code>-1</code></dt>
 
87
      <dd><code>0x01 <strong>0x83</strong></code></dd>
 
88
      <dt><code>1.5</code></dt>
 
89
      <dd><code><strong>0x84</strong> 0x3f 0xf8 0x00 0x00 0x00 0x00 0x00 0x00</code></dd>
 
90
      <dt><code>&quot;hello&quot;</code></dt>
 
91
      <dd><code>0x05 <strong>0x82</strong> 0x68 0x65 0x6c 0x6c 0x6f</code></dd>
 
92
      <dt><code>[]</code></dt>
 
93
      <dd><code>0x00 <strong>0x80</strong></code></dd>
 
94
      <dt><code>[1, 23]</code></dt>
 
95
      <dd><code>0x02 <strong>0x80</strong> 0x01 <strong>0x81</strong> 0x17 <strong>0x81</strong></code></dd>
 
96
      <dt><code>123456789123456789</code></dt>
 
97
      <dd><code>0x15 0x3e 0x41 0x66 0x3a 0x69 0x26 0x5b 0x01 <strong>0x85</strong></code></dd>
 
98
      <dt><code>[1, [&quot;hello&quot;]]</code></dt>
 
99
      <dd><code>0x02 <strong>0x80</strong> 0x01 <strong>0x81</strong> 0x01 <strong>0x80</strong> 0x05 <strong>0x82</strong> 0x68 0x65 0x6c 0x6c 0x6f</code></dd>
 
100
    </dl>
 
101
 
 
102
    <h2>Profiles<a name="auto4"/></h2>
 
103
    
 
104
    <p>
 
105
      The Banana protocol is extendable. Therefore, it supports the concept of profiles. Profiles allow
 
106
      developers to extend the banana protocol, adding new element types, while still keeping backwards
 
107
      compatability with implementations that don't support the extensions. The profile used in each
 
108
      session is determined at the handshake stage (see below.)
 
109
    </p>
 
110
 
 
111
    <p>
 
112
      A profile is specified by a unique string. This specification defines two profiles
 
113
      - <code>&quot;none&quot;</code> and <code>&quot;pb&quot;</code>. The <code>&quot;none&quot;</code> profile is the standard
 
114
      profile that should be supported by all Banana implementations.
 
115
      Additional profiles may be added in the future.
 
116
    </p>
 
117
    
 
118
    <h3>The <code>&quot;none&quot;</code> Profile<a name="auto5"/></h3>
 
119
 
 
120
    <p>
 
121
      The <code>&quot;none&quot;</code> profile is identical to the delimiter types listed above. It is highly recommended
 
122
      that all Banana clients and servers support the <code>&quot;none&quot;</code> profile.
 
123
    </p>
 
124
 
 
125
    <h3>The <code>&quot;pb&quot;</code> Profile<a name="auto6"/></h3>
 
126
 
 
127
    <p>
 
128
      The <code>&quot;pb&quot;</code> profile is intended for use with the Perspective Broker protocol, that runs on top
 
129
      of Banana. Basically, it converts commonly used PB strings into shorter versions, thus
 
130
      minimizing bandwidth usage. It starts with a single byte, which tells us to which string element
 
131
      to convert it, and ends with the delimiter byte, <code>0x87</code>, which should not be prefixed
 
132
      by a length.
 
133
    </p>
 
134
    
 
135
    <dl>
 
136
      <dt>0x01</dt> <dd>'None'</dd>
 
137
      <dt>0x02</dt> <dd>'class'</dd>
 
138
      <dt>0x03</dt> <dd>'dereference'</dd>
 
139
      <dt>0x04</dt> <dd>'reference'</dd>
 
140
      <dt>0x05</dt> <dd>'dictionary'</dd>
 
141
      <dt>0x06</dt> <dd>'function'</dd>
 
142
      <dt>0x07</dt> <dd>'instance'</dd>
 
143
      <dt>0x08</dt> <dd>'list'</dd>
 
144
      <dt>0x09</dt> <dd>'module'</dd>
 
145
      <dt>0x0a</dt> <dd>'persistent'</dd>
 
146
      <dt>0x0b</dt> <dd>'tuple'</dd>
 
147
      <dt>0x0c</dt> <dd>'unpersistable'</dd>
 
148
      <dt>0x0d</dt> <dd>'copy'</dd>
 
149
      <dt>0x0e</dt> <dd>'cache'</dd>
 
150
      <dt>0x0f</dt> <dd>'cached'</dd>
 
151
      <dt>0x10</dt> <dd>'remote'</dd>
 
152
      <dt>0x11</dt> <dd>'local'</dd>
 
153
      <dt>0x12</dt> <dd>'lcache'</dd>
 
154
      <dt>0x13</dt> <dd>'version'</dd>
 
155
      <dt>0x14</dt> <dd>'login'</dd>
 
156
      <dt>0x15</dt> <dd>'password'</dd>
 
157
      <dt>0x16</dt> <dd>'challenge'</dd>
 
158
      <dt>0x17</dt> <dd>'logged_in'</dd>
 
159
      <dt>0x18</dt> <dd>'not_logged_in'</dd>
 
160
      <dt>0x19</dt> <dd>'cachemessage'</dd>
 
161
      <dt>0x1a</dt> <dd>'message'</dd>
 
162
      <dt>0x1b</dt> <dd>'answer'</dd>
 
163
      <dt>0x1c</dt> <dd>'error'</dd>
 
164
      <dt>0x1d</dt> <dd>'decref'</dd>
 
165
      <dt>0x1e</dt> <dd>'decache'</dd>
 
166
      <dt>0x1f</dt> <dd>'uncache'</dd>
 
167
      </dl>
 
168
 
 
169
    <h2>Protocol Handshake and Behaviour<a name="auto7"/></h2>
 
170
 
 
171
    <p>
 
172
      The initiating side of the connection will be referred to as <q>client</q>, and the other
 
173
      side as <q>server</q>.
 
174
    </p>
 
175
 
 
176
    <p>
 
177
      Upon connection, the server will send the client a list of string elements, signifying
 
178
      the profiles it supports. It is recommended that <code>&quot;none&quot;</code> be included in this list. The client
 
179
      then sends the server a string from this list, telling the server which profile it wants to
 
180
      use. At this point the whole session will use this profile.
 
181
    </p>
 
182
    
 
183
    <p>
 
184
      Once a profile has been established, the two sides may start exchanging elements. There is no
 
185
      limitation on order or dependencies of messages. Any such limitation (e.g. <q>server can only
 
186
      send an element to client in response to a request from client</q>) is application specific.
 
187
    </p>
 
188
 
 
189
    <p>
 
190
      Upon receiving illegal messages, failed handshakes, etc., a Banana client or server should
 
191
      close its connection.
 
192
    </p>
 
193
 
 
194
  </div>
 
195
 
 
196
    <p><a href="../howto/index.html">Index</a></p>
 
197
    <span class="version">Version: 10.0.0</span>
 
198
  </body>
 
199
</html>
 
 
b'\\ No newline at end of file'