summaryrefslogtreecommitdiff
path: root/doc/en/weechat_relay_protocol.en.txt
blob: 3f8e56a998b4f807abc7f6c0235bfda7822ca5ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
WeeChat Relay Protocol
======================
Sébastien Helleu <flashcode@flashtux.org>


This document is the specification of WeeChat relay protocol: the protocol used
to relay WeeChat data to clients, which are mostly remote interfaces.


[[introduction]]
Introduction
------------

[[terminology]]
Terminology
~~~~~~~~~~~

The following terms are used in this document:

* 'relay': this is the WeeChat with relay plugin, which acts as "server" and
  allows 'clients' to connect
* 'client': this is another software, connected to 'relay' via a network
  connection; in most cases, this 'client' is a remote interface

[[network_diagram]]
Network diagram
~~~~~~~~~~~~~~~

The 'clients' are connected to 'relay' like shown in this diagram:

.......................................
                                                      ┌──────────┐
 ┌────────┐                                     ┌─────┤ client 1 │ Workstation (Linux, BSD, Mac OS X, Windows, ...)
 │  irc   │◄───┐   ╔═════════════╤═══════╗      │     └──────────┘
 └────────┘    └───╢             │       ║◄─────┘     ┌──────────┐
   ......          ║   WeeChat   │ Relay ║◄───────────┤ client 2 │ Mobile device (Android, iPhone, ...)
 ┌────────┐    ┌───╢             │       ║◄─────┐     └──────────┘
 │ jabber │◄───┘   ╚═════════════╧═══════╝      │        ......
 └────────┘                                     │     ┌──────────┐
   ......                                       └─────┤ client N │ Other devices
                                                      └──────────┘


└─────────────┘    └─────────────────────┘╘══════════╛└──────────────────────┘
network servers       ncurses interface      relay       remote interfaces
                                            protocol
........................................

[NOTE]
All clients here are clients using 'weechat' protocol in 'relay' plugin. The
'relay' plugin also allows IRC clients, then 'relay' plugin acts as an
'irc proxy' (not described in this document).

[[protocol_generalities]]
Protocol generalities
---------------------

* Connections from 'client' to 'relay' are made using TCP sockets on IP/port
  used by 'relay' plugin to listen to new connections
  (option 'relay.port.weechat' in WeeChat).
* Number of 'clients' is not limited.
* Each 'client' is independent from other clients.
* Messages from 'client' to 'relay' are called 'commands', they are sent as text
  (a string).
* Messages from 'relay' to 'client' are called 'messages', they are sent as
  binary data.

[[commands]]
Commands (client → relay)
-------------------------

Commands have format: "(id) command arguments\n".

Fields are:

* 'id': optional message identifier that will be sent in answer from 'relay';
  it must be enclosed in parentheses, and must not start with an underscore
  ("_") (ids starting with underscore are reserved for WeeChat 'event' messages)
* 'command': a command (see table below)
* 'arguments': optional arguments for command (many arguments are separated by
  spaces)

List of available commands (detail in next chapters):

[width="60%",cols="^3m,14",options="header"]
|=====================================================
| Command  | Description
| init     | Initialize connection with 'relay'
| hdata    | Request hdata
| info     | Request info
| infolist | Request infolist
| nicklist | Request nicklist
| input    | Send data to a buffer (text or command)
| sync     | Synchronize buffer(s) (get updates for buffer(s))
| desync   | Desynchronize buffer(s) (stop updates for buffer(s))
| quit     | Disconnect from 'relay'
|=====================================================

[[command_init]]
init
~~~~

Initialize connection with 'relay'. This must be first command sent to 'relay'.
If not sent, 'relay' will close connection on first command received, without
warning.

Syntax:

----------------------------------------
init [<option>=<value>,[<option>=<value>,...]]
----------------------------------------

Arguments:

* 'option': one of following options:
** 'password' (required): password used to authenticate on 'relay' (option
   'relay.network.password' in WeeChat)
** 'compression' (optional): compression type:
*** 'gzip': enable gzip compression for messages sent by 'relay'
*** 'off': disable compression

[NOTE]
Compression 'gzip' is enabled by default if 'relay' supports gzip compression.

Example:

----------------------------------------
init password=mypass,compression=gzip
----------------------------------------

[[command_hdata]]
hdata
~~~~~

Request hdata.

Syntax:

----------------------------------------
(id) hdata <path> [<keys>]
----------------------------------------

Arguments:

* 'path': path to a hdata, with format: "hdata:pointer/var/var/.../var", the
  last var is the hdata returned:
** 'hdata': name of hdata
** 'pointer': pointer ("0x12345") or list name (for example: "gui_buffers")
   (count allowed, see below)
** 'var': a variable name in parent hdata (previous name in path)
   (count allowed, see below)
* 'keys': comma-separated list of keys to return in hdata returned (if not
  specified, all keys are returned, which is not recommended on large hdata
  structures)

A count is allowed after pointer and variables, with format "(N)". Possible
values are:

* positive number: iterate using next element, N times
* negative number: iterate using previous element, N times
* '*': iterate using next element, until end of list

Examples:

----------------------------------------
# request all buffers, hdata of type "buffer" is returned
# keys number and name are returned for each buffer
hdata buffer:gui_buffers(*) number,name

# request all lines of all buffers, hdata of type "line_data" is returned
# all keys are returned
hdata buffer:gui_buffers(*)/lines/first_line(*)/data

# request full_name of first buffer
hdata buffer:gui_buffers full_name
----------------------------------------

[[command_info]]
info
~~~~

Request info.

Syntax:

----------------------------------------
(id) info <name>
----------------------------------------

Arguments:

* 'name': name of info to retrieve

Example:

----------------------------------------
info version
----------------------------------------

[[command_infolist]]
infolist
~~~~~~~~

Request infolist.

[IMPORTANT]
Content of infolist is a duplication of actual data. Wherever possible, use
command <<command_hdata,hdata>>, which is direct access to data (it is
faster, uses less memory and returns smaller objects in message).

Syntax:

----------------------------------------
(id) infolist <name> <arguments>
----------------------------------------

Arguments:

* 'name': name of infolist to retrieve
* 'arguments': arguments for infolist

Example:

----------------------------------------
infolist buffer
----------------------------------------

[[command_nicklist]]
nicklist
~~~~~~~~

Request nicklist, for one or all buffers.

Syntax:

----------------------------------------
(id) nicklist [<buffer>]
----------------------------------------

Arguments:

* 'buffer': pointer ('0x12345') or full name of buffer (for example:
  'core.weechat' or 'irc.freenode.#weechat')

Examples:

----------------------------------------
# request nicklist for all buffers
nicklist

# request nicklist for irc.freenode.#weechat
nicklist irc.freenode.#weechat
----------------------------------------

[[command_input]]
input
~~~~~

Send data to a buffer.

Syntax:

----------------------------------------
input <buffer> <data>
----------------------------------------

Arguments:

* 'buffer': pointer ('0x12345') or full name of buffer (for example:
  'core.weechat' or 'irc.freenode.#weechat')
* 'data': data to send to buffer: if beginning by '/', this will be executed as
   a command on buffer, otherwise text is sent as input of buffer

Examples:

----------------------------------------
input core.weechat /help filter
input irc.freenode.#weechat hello guys!
----------------------------------------

[[command_sync]]
sync
~~~~

_Updated in version 0.4.1._

Synchronize one or more buffers, to get updates.

[IMPORTANT]
It is recommended to send this command immediately after you asked
data for buffers (lines, ...). It can be send in same message (after a new
line).

Syntax:

----------------------------------------
sync [<buffer>[,<buffer>...] <option>[,<option>...]]
----------------------------------------

Arguments:

* 'buffer': pointer ('0x12345') or full name of buffer (for example:
  'core.weechat' or 'irc.freenode.#weechat'); name "*" can be used to
  specify all buffers
* 'options': one of following keywords, separated by commas (default is
  'buffers,upgrade,buffer,nicklist' for "*" and 'buffer,nicklist' for a buffer):
** 'buffers': receive signals about buffers (opened/closed, moved, renamed,
   merged/unmerged, renamed); this can be used only with name "*"
   (_new in version 0.4.1_)
** 'upgrade': receive signals about WeeChat upgrade (upgrade, upgrade ended);
   this can be used only with name "*"
   (_new in version 0.4.1_)
** 'buffer': receive signals about buffer (new lines, type changed, title
    changed, local variable added/removed, and same signals as 'buffers' for the
    buffer) (_updated in version 0.4.1_)
** 'nicklist': receive nicklist after changes

Examples:

----------------------------------------
# synchronize all buffers with nicklist
# (the 3 commands are equivalent, but the first one is recommended
# for compatibility with future versions)
sync
sync *
sync * buffers,upgrade,buffer,nicklist

# synchronize core buffer
sync core.buffer

# synchronize #weechat channel, without nicklist
sync irc.freenode.#weechat buffer

# get general signals + all signals for #weechat channel
sync * buffers,upgrade
sync irc.freenode.#weechat
----------------------------------------

[[command_desync]]
desync
~~~~~~

_Updated in version 0.4.1._

Desynchronize one or more buffers, to stop updates.

[NOTE]
This will remove 'options' for buffers. If some options are still active for
buffers, the client will still receive updates for buffers.

Syntax:

----------------------------------------
desync [<buffer>[,<buffer>...] <option>[,<option>...]]
----------------------------------------

Arguments:

* 'buffer': pointer ('0x12345') or full name of buffer (for example:
  'core.weechat' or 'irc.freenode.#weechat'); name "*" can be used to
  specify all buffers
* 'options': one of following keywords, separated by commas (default is
  'buffers,upgrade,buffer,nicklist' for "*" and 'buffer,nicklist' for a buffer);
  see <<command_sync,command sync>> for values.

[NOTE]
When using buffer "*", the other buffers synchronized (using a name) are kept. +
So if you send: "sync *", then "sync irc.freenode.#weechat", then "desync *",
the updates on #weechat channel will still be sent by WeeChat (you must remove
it explicitly to stop updates).

Examples:

----------------------------------------
# desynchronize all buffers
# (the 3 commands are equivalent, but the first one is recommended
# for compatibility with future versions)
desync
desync *
desync * buffers,upgrade,buffer,nicklist

# desynchronize nicklist for #weechat channel (keep buffer updates)
desync irc.freenode.#weechat nicklist

# desynchronize #weechat channel
desync irc.freenode.#weechat
----------------------------------------

[[command_test]]
test
~~~~

Test command: WeeChat will reply with various different objects.

This command is useful to test the decoding of objects returned by WeeChat.

[IMPORTANT]
You must not use the pointer values returned by this command, they are not
valid. This command should only be used to test decoding of a message sent by
WeeChat.

Syntax:

----------------------------------------
test
----------------------------------------

Example:

----------------------------------------
test
----------------------------------------

Returned objects (in this order):

[width="60%",cols="^3,3m,7m",options="header"]
|=====================================================
| Type              | Type (in message) | Value
| char              | chr               | 65 ("A")
| integer           | int               | 123456
| long              | lon               | 1234567890
| string            | str               | "a string"
| string            | str               | ""
| string            | str               | NULL
| buffer            | buf               | "buffer"
| buffer            | buf               | NULL
| pointer           | ptr               | 0x1234abcd
| pointer           | ptr               | NULL
| time              | tim               | 1321993456
| array of strings  | arr str           | { "abc", "de" }
| array of integers | arr int           | { 123, 456, 789 }
|=====================================================

[[command_quit]]
quit
~~~~

Disconnect from 'relay'.

Syntax:

----------------------------------------
quit
----------------------------------------

Example:

----------------------------------------
quit
----------------------------------------

[[messages]]
Messages (relay → client)
-------------------------

Messages are sent as binary data, using following format (with size in bytes):

.......................................
┌────────╥─────────────╥────╥────────┬──────────╥───────╥────────┬──────────┐
│ length ║ compression ║ id ║ type 1 │ object 1 ║  ...  ║ type N │ object N │
└────────╨─────────────╨────╨────────┴──────────╨───────╨────────┴──────────┘
 └──────┘ └───────────┘ └──┘ └──────┘ └────────┘         └──────┘ └────────┘
     4          1        ??      3        ??                 3        ??
 └────────────────────┘ └──────────────────────────────────────────────────┘
       header (5)                        compressed data (??)
 └─────────────────────────────────────────────────────────────────────────┘
                               'length' bytes
.......................................

* 'length' (unsigned integer): number of bytes of whole message (including
  this length)
* 'compression' (byte): flag:
** '0x00': following data is not compressed
** '0x01': following data is gzip-compressed
* 'id' (string): identifier sent by client (before command name); it can be
  empty (string with zero length and no content) if no identifier was given in
  command
* 'type' (3 chars): a type: 3 letters (see table below)
* 'object': an object (see table below)

[[message_compression]]
Compression
~~~~~~~~~~~

If flag 'compression' is equal to 0x01, then *all* data after is compressed
with gzip, and therefore must be uncompressed before being processed.

[[message_identifier]]
Identifier
~~~~~~~~~~

There are two different identifiers ('id'):

* 'id' sent by 'client': 'relay' will answer with same 'id' in its answer
* 'id' of an event: on some events, 'relay' will send message to 'client' using
  a specific 'id', beginning with underscore (see table below)

WeeChat reserved identifiers:

[width="100%",cols="5m,5,3,3,10,8",options="header"]
|=====================================================
| Identifier | Description | Received with sync | Hdata type | Hdata content
| Recommended action in client

| _buffer_opened | Buffer opened | buffers / buffer | buffer |
  'number' (integer), 'full_name' (string), 'short_name' (string), +
  'nicklist' (integer), 'title' (string), 'local_variables' (hashtable), +
  'prev_buffer' (pointer), 'next_buffer' (pointer) |
  Open buffer

| _buffer_moved | Buffer moved | buffers / buffer | buffer |
  'number' (integer), 'full_name' (string), +
  'prev_buffer' (pointer), 'next_buffer' (pointer) |
  Move buffer

| _buffer_merged | Buffer merged | buffers / buffer | buffer |
  'number' (integer), 'full_name' (string), +
  'prev_buffer' (pointer), 'next_buffer' (pointer) |
  Merge buffer

| _buffer_unmerged | Buffer unmerged | buffers / buffer | buffer |
  'number' (integer), 'full_name' (string), +
  'prev_buffer' (pointer), 'next_buffer' (pointer) |
  Unmerge buffer

| _buffer_renamed | Buffer renamed | buffers / buffer | buffer |
  'number' (integer), 'full_name' (string), 'short_name' (string),
  'local_variables' (hashtable) |
  Rename buffer

| _buffer_title_changed | Title of buffer changed | buffers / buffer | buffer |
  'number' (integer), 'full_name' (string), 'title' (string) |
  Change title of buffer

| _buffer_closing | Buffer closing | buffers / buffer | buffer |
  'number' (integer), 'full_name' (string) |
  Close buffer

| _buffer_type_changed | Type of buffer changed | buffer | buffer |
  'number' (integer), 'full_name' (string), +
  'type' (integer) |
  Change type of buffer

| _buffer_localvar_added | Local variable added | buffer | buffer |
  'number' (integer), 'full_name' (string), 'local_variables' (hashtable) |
  Add local variable in buffer

| _buffer_localvar_changed | Local variable changed | buffer | buffer |
  'number' (integer), 'full_name' (string), 'local_variables' (hashtable) |
  Change local variable in buffer

| _buffer_localvar_removed | Local variable removed | buffer | buffer |
  'number' (integer), 'full_name' (string), 'local_variables' (hashtable) |
  Remove local variable from buffer

| _buffer_line_added | Line added in buffer | buffer | line |
  'buffer' (pointer), 'date' (time), 'date_printed' (time), 'displayed' (char),
  'highlight' (char), 'tags_array' (array of strings), 'prefix' (string),
  'message' (string) |
  Display line in buffer

| _nicklist | Nicklist for a buffer | nicklist | nicklist_item |
  'group' (char), 'visible' (char), 'level' (integer), +
  'name' (string), 'color' (string), +
  'prefix' (string), 'prefix_color' (string) |
  Update nicklist

| _upgrade | WeeChat is upgrading +
  (_new in version 0.3.8_) | upgrade | (empty) |
  (empty) |
  Desync from WeeChat (send command 'desync')

| _upgrade_ended | Upgrade of WeeChat done +
  (_new in version 0.3.8_) | upgrade | (empty) |
  (empty) |
  Resync with WeeChat (resend all commands sent on startup after the 'init')
|=====================================================

[[message_objects]]
Objects
~~~~~~~

Objects are identified by 3 letters, called 'type'. Following types are
available:

[width="60%",cols="^2m,5,7",options="header"]
|=====================================================
| Type | Value                | Length
| chr  | Signed char          | 1 byte
| int  | Signed integer       | 4 bytes
| lon  | Signed long integer  | 1 byte + length of long as string
| str  | String               | 4 bytes + length of string (without final '\0')
| buf  | Buffer of bytes      | 4 bytes + length of data
| ptr  | Pointer              | 1 byte + length of pointer as string
| tim  | Time                 | 1 byte + length of time as string
| htb  | Hashtable            | Variable
| hda  | Hdata content        | Variable
| inf  | Info: name + content | Variable
| inl  | Infolist content     | Variable
| arr  | Array of values      | 3 bytes (type) + number of items + data
|=====================================================

[[object_char]]
Char
^^^^

A signed char is 1 byte.

Example:

.......................................
┌────┐
│ 41 │ ────► 65 (0x41: "A")
└────┘
.......................................

[[object_integer]]
Integer
^^^^^^^

A signed integer is 4 bytes, encoded as big-endian format (most significant byte
first).

Example:

.......................................
┌────┬────┬────┬────┐
│ 00 │ 00 │ 01 │ 04 │ ────► 260 (0x104)
└────┴────┴────┴────┘
.......................................

[[object_long_integer]]
Long integer
^^^^^^^^^^^^

A signed long integer is encoded as a string, with length on one byte.

Example:

.......................................
┌────╥────┬────┬────┐
│ 03 ║ 32 │ 36 │ 30 │ ────► 260
└────╨────┴────┴────┘
 └──┘ └────────────┘
length '2'  '6'  '0'
.......................................

[[object_string]]
String
^^^^^^

A string is a length (integer on 4 bytes) + content of string (without final '\0').

Example:

.......................................
┌────┬────┬────┬────╥────┬────┬────┬────┬────┐
│ 00 │ 00 │ 00 │ 05 ║ 68 │ 65 │ 6C │ 6C │ 6F │ ────► "hello"
└────┴────┴────┴────╨────┴────┴────┴────┴────┘
 └─────────────────┘ └──────────────────────┘
       length         'h'  'e'  'l'  'l'  'o'
.......................................

An empty string has a length of zero:

.......................................
┌────┬────┬────┬────┐
│ 00 │ 00 │ 00 │ 00 │ ────► ""
└────┴────┴────┴────┘
 └─────────────────┘
       length
.......................................

A 'NULL' string (NULL pointer in C) has a length of -1:

.......................................
┌────┬────┬────┬────┐
│ FF │ FF │ FF │ FF │ ────► NULL
└────┴────┴────┴────┘
 └─────────────────┘
       length
.......................................

[[object_buffer]]
Buffer
^^^^^^

Same format as <<object_string,string>>; content is just an array of bytes.

[[object_pointer]]
Pointer
^^^^^^^

A pointer is encoded as string (hex), with length on one byte.

Example:

.......................................
┌────╥────┬────┬────┬────┬────┬────┬────┬────┬────┐
│ 09 ║ 31 │ 61 │ 32 │ 62 │ 33 │ 63 │ 34 │ 64 │ 35 │ ────► 0x1a2b3c4d5
└────╨────┴────┴────┴────┴────┴────┴────┴────┴────┘
 └──┘ └──────────────────────────────────────────┘
length '1'  'a'  '2'  'b'  '3'  'c'  '4'  'd'  '5'
.......................................

A 'NULL' pointer has a length of zero:

.......................................
┌────╥────┐
│ 01 ║ 00 │ ────► NULL (0x0)
└────╨────┘
 └──┘ └──┘
length  0
.......................................

[[object_time]]
Time
^^^^

A time (number of seconds) is encoded as a string, with length on one byte.

Example:

.......................................
┌────╥────┬────┬────┬────┬────┬────┬────┬────┬────┬────┐
│ 0A ║ 31 │ 33 │ 32 │ 31 │ 39 │ 39 │ 33 │ 34 │ 35 │ 36 │ ────► 1321993456
└────╨────┴────┴────┴────┴────┴────┴────┴────┴────┴────┘
 └──┘ └───────────────────────────────────────────────┘
length '1'  '3'  '2'  '1'  '9'  '9'  '3'  '4'  '5'  '6'
.......................................

[[object_hashtable]]
Hashtable
^^^^^^^^^

A hashtable contains type for keys, type for values, number of items in
hashtable (integer on 4 bytes), and then keys and values of items.

.......................................
┌───────────┬─────────────┬───────╥───────┬─────────╥─────╥───────┬─────────┐
│ type_keys │ type_values │ count ║ key 1 │ value 1 ║ ... ║ key N │ value N │
└───────────┴─────────────┴───────╨───────┴─────────╨─────╨───────┴─────────┘
.......................................

Example:

.......................................
┌─────┬─────┬───╥──────┬─────╥──────┬─────┐
│ str │ str │ 2 ║ key1 │ abc ║ key2 │ def │ ────► { 'key1' => 'abc', 'key2' => 'def' }
└─────┴─────┴───╨──────┴─────╨──────┴─────┘
 └───┘ └───┘ └─┘ └──────────┘ └──────────┘
 type  type count   item 1       item 2
 keys values
.......................................

[[object_hdata]]
Hdata
^^^^^

A 'hdata' contains a path with hdata names, list of keys, number of set of
objects, and then set of objects (path with pointers, then objects).

.......................................
┌────────┬──────┬───────╥────────┬─────────────────────╥────────┬─────────────────────╥─────┐
│ h-path │ keys │ count ║ p-path │ value 1 ... value N ║ p-path │ value 1 ... value N ║ ... │
└────────┴──────┴───────╨────────┴─────────────────────╨────────┴─────────────────────╨─────┘
.......................................

* 'name' (string): name of hdata ('buffer', 'window', 'bar', ...)
* 'h-path' (string): path used to reach hdata (example:
  'buffer/lines/line/line_data'); the last element in path is the hdata returned
* 'keys' (string): string with list of 'key:type' (separated by commas),
  example: 'number:int,name:str'
* 'count' (integer): number of set of objects
* 'p-path': path with pointers to objects (number of pointers here is number of
  elements in path)
* 'values': list of values (number of values is number of keys returned for
  hdata)

Example of hdata with 2 buffers (weechat core and freenode server) and two keys
('number' and 'full_name'):

.......................................
# command
hdata buffer:gui_buffers(*) number,full_name

# response
┌────────┬──────────────────────────┬───╥─────────┬───┬──────────────╥─────────┬───┬────────────────────┐
│ buffer │ number:int,full_name:str │ 2 ║ 0x12345 │ 1 │ core.weechat ║ 0x6789a │ 2 │irc.server.freenode │
└────────┴──────────────────────────┴───╨─────────┴───┴──────────────╨─────────┴───┴────────────────────┘
 └──────┘ └────────────────────────┘ └─┘ └──────────────────────────┘ └────────────────────────────────┘
  hpath           keys              count          buffer 1                        buffer 2
.......................................

Example of hdata with lines of core buffer:

.......................................
# command
hdata buffer:gui_buffers(*)/lines/first_line(*)/data

# response
┌─────────────────────────────┬─────┬────╥──
│ buffer/lines/line/line_data │ ... │ 50 ║ ...
└─────────────────────────────┴─────┴────╨──
 └───────────────────────────┘ └───┘ └──┘
      h-path (hdata names)     keys  count

  ──╥───────────┬───────────┬───────────┬───────╥───────────┬───────────┬───────────┬───────╥──────────────┐
... ║ 0x23cf970 │ 0x23cfb60 │ 0x23d5f40 │ ..... ║ 0x23cf970 │ 0x23cfb60 │ 0x23d6110 │ ..... ║ ............ │
  ──╨───────────┴───────────┴───────────┴───────╨───────────┴───────────┴───────────┴───────╨──────────────┘
     └─────────────────────────────────┘ └─────┘ └─────────────────────────────────┘ └─────┘
              p-path (pointers)          objects          p-path (pointers)          objects
     └─────────────────────────────────────────┘ └─────────────────────────────────────────┘ └────────────┘
                        line 1                                      line 2                     lines 3-50
.......................................

Example of hdata with nicklist:

.......................................
# command
nicklist

# response
┌───────────────────┬────────────────────────────────────────────────────────────────────────────────┬────╥──
│ buffer/nick_group │ group:chr,visible:chr,name:str,color:str,prefix:str,prefix_color:str,level:int │ 12 ║ ...
└───────────────────┴────────────────────────────────────────────────────────────────────────────────┴────╨──
 └─────────────────┘ └──────────────────────────────────────────────────────────────────────────────┘ └──┘
        h-path                                            keys                                        count

  ──╥─────────┬─────────┬───┬───┬──────┬─┬─┬─┬───╥─────────┬─────────┬───┬───┬───────┬─┬─┬─┬───╥──
... ║ 0x12345 │ 0x6789a │ 1 │ 0 │ root │ │ │ │ 0 ║ 0x123cf │ 0x678d4 │ 1 │ 0 │ 000|o │ │ │ │ 1 ║ ...
  ──╨─────────┴─────────┴───┴───┴──────┴─┴─┴─┴───╨─────────┴─────────┴───┴───┴───────┴─┴─┴─┴───╨──
     └─────────────────┘ └──────────────────────┘ └─────────────────┘ └───────────────────────┘
            p-path               objects                 p-path                objects
     └──────────────────────────────────────────┘ └───────────────────────────────────────────┘
                 group (nicklist root)                          group (channel ops)

  ──╥─────────┬─────────┬───┬───┬──────────┬──────┬───┬────────────┬───╥──
... ║ 0x128a7 │ 0x67ab2 │ 0 │ 1 │ ChanServ │ blue │ @ │ lightgreen │ 0 ║ ...
  ──╨─────────┴─────────┴───┴───┴──────────┴──────┴───┴────────────┴───╨──
     └─────────────────┘ └────────────────────────────────────────────┘
            p-path                          objects
     └────────────────────────────────────────────────────────────────┘
                              nick (@ChanServ)
.......................................

[[object_info]]
Info
^^^^

A 'info' contains a name and a value (both are strings).

.......................................
┌──────┬───────┐
│ name │ value │
└──────┴───────┘
.......................................

* 'name' (string): name of info
* 'value' (string): value

Example of info 'version':

.......................................
┌─────────┬───────────────────┐
│ version │ WeeChat 0.3.7-dev │
└─────────┴───────────────────┘
.......................................

[[object_infolist]]
Infolist
^^^^^^^^

A 'infolist' contains a name, number of items, and then items (set of
variables).

.......................................
┌──────┬───────╥────────╥─────╥────────┐
│ name │ count ║ item 1 ║ ... ║ item N │
└──────┴───────╨────────╨─────╨────────┘
.......................................

An item is:

.......................................
┌───────╥────────┬────────┬─────────╥─────╥────────┬────────┬─────────┐
│ count ║ name 1 │ type 1 │ value 1 ║ ... ║ name N │ type N │ value N │
└───────╨────────┴────────┴─────────╨─────╨────────┴────────┴─────────┘
.......................................

* 'name' (string): name of infolist ('buffer', 'window', 'bar', ...)
* 'count' (integer): number of items
* 'item':
** 'count': number of variables in item
** 'name': name of variable
** 'type': type of variable ('int', 'str', ...)
** 'value': value of variable

Example of infolist with 2 buffers (weechat core and freenode server):

.......................................
# command
infolist buffer

# response
┌────────┬───╥────┬─────────┬─────┬─────────┬─────╥────┬─────────┬─────┬─────────┬─────┐
│ buffer │ 2 ║ 42 │ pointer │ ptr │ 0x12345 │ ... ║ 42 │ pointer │ ptr │ 0x6789a │ ... │
└────────┴───╨────┴─────────┴─────┴─────────┴─────╨────┴─────────┴─────┴─────────┴─────┘
 └──────┘ └─┘ └──────────────────────────────────┘ └──────────────────────────────────┘
   name  count              item 1                               item 2
.......................................

[[object_array]]
Array
^^^^^

An array is a type (3 bytes) + number of items (integer on 4 bytes) + data.

Example of array with 2 strings:

.......................................
┌─────╥────┬────┬────┬────╥────┬────┬────┬────╥────┬────┬────╥────┬────┬────┬────╥────┬────┐
│ str ║ 00 │ 00 │ 00 │ 02 ║ 00 │ 00 │ 00 │ 03 ║ 61 │ 62 │ 63 ║ 00 │ 00 │ 00 │ 02 ║ 64 │ 65 │ ────► { "abc", "de" }
└─────╨────┴────┴────┴────╨────┴────┴────┴────╨────┴────┴────╨────┴────┴────┴────╨────┴────┘
 └───┘ └─────────────────┘ └─────────────────┘ └────────────┘ └─────────────────┘ └───────┘
 type   number of strings        length         'a'  'b'  'c'       length         'd'  'e'
.......................................

Example of array with 3 integers:

.......................................
┌─────╥────┬────┬────┬────╥────┬────┬────┬────╥────┬────┬────┬────╥────┬────┬────┬────┐
│ int ║ 00 │ 00 │ 00 │ 03 ║ 00 │ 00 │ 00 │ 7B ║ 00 │ 00 │ 01 │ C8 ║ 00 │ 00 │ 03 │ 15 │ ────► { 123, 456, 789 }
└─────╨────┴────┴────┴────╨────┴────┴────┴────╨────┴────┴────┴────╨────┴────┴────┴────┘
 └───┘ └─────────────────┘ └─────────────────┘ └─────────────────┘ └─────────────────┘
 type   number of integers      123 (0x7B)         456 (0x1C8)         789 (0x315)
.......................................

A 'NULL' array:

.......................................
┌─────╥────┬────┬────┬────┐
│ str ║ 00 │ 00 │ 00 │ 00 │ ────► NULL
└─────╨────┴────┴────┴────┘
 └───┘ └─────────────────┘
 type   number of strings
.......................................

[[typical_session]]
Typical session
---------------

.......................................
          ┌────────┐                               ┌───────┐                  ┌─────────┐
          │ Client ├ ─ ─ ─ ─ ─ (network) ─ ─ ─ ─ ─ ┤ Relay ├──────────────────┤ WeeChat │
          └────────┘                               └───────┘                  └─────────┘
               ║                                       ║                           ║
               ╟─────────────────────────────────────► ║                           ║
               ║ open socket                           ║ add client                ║
               ║                                       ║                           ║
               ╟─────────────────────────────────────► ║                           ║
               ║ cmd: init password=xxx,...            ║ init/allow client         ║
               ║                                       ║                           ║
               ╟─────────────────────────────────────► ║                           ║
               ║ cmd: hdata buffer ...                 ╟─────────────────────────► ║
               ║      sync ...                         ║ request hdata             ║ read hdata values
               ║                                       ║                           ║
               ║                                       ║ ◄─────────────────────────╢
               ║ ◄─────────────────────────────────────╢                     hdata ║
create buffers ║                       msg: hda buffer ║                           ║
               ║                                       ║                           ║
               ║                ........               ║          ........         ║
               ║                                       ║                           ║
               ╟─────────────────────────────────────► ║                           ║
               ║ cmd: input ...                        ╟─────────────────────────► ║
               ║                                       ║ send data to buffer       ║ send data to buffer
               ║                                       ║                           ║
               ║                ........               ║          ........         ║
               ║                                       ║                           ║ signal received
               ║                                       ║ ◄─────────────────────────╢ (hooked by relay)
               ║ ◄─────────────────────────────────────╢                signal XXX ║
update buffers ║                msg: id: "_buffer_..." ║                           ║
               ║                                       ║                           ║
               ║                ........               ║          ........         ║
               ║                                       ║                           ║
               ╟─────────────────────────────────────► ║                           ║
               ║ cmd: quit                             ║ disconnect client         ║
               ║                                       ║                           ║
.......................................