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
|
==================
Network Encoding
==================
This describes the encoding used to serialize data. It doesn't cover specific
objects/messages but focuses on the base types.
The types are not self documenting in any way. They can not be decoded unless
you know what they are.
Conventions
===========
Integers
--------
The integer types used will be named ``{signed}{size}{endian}``. For example
``u16le`` is an unsigned 16 bit integer encoded in little endian byte order
while ``s64be`` is a signed 64 bit integer in big endian. Additionally ``u8``
and ``s8`` will represent signed and unsigned bytes respectively. Signed
integers use two's complement encoding.
Complex Types
-------------
This document will use a c-like syntax for describing structures. The
structure represents the data that will go over the wire. There will be no
padding between the elements and the elements will be sent in the order they
appear. For example::
struct foo {
u8 tag;
u32le data;
}
When encoding the values ``0x05`` and ``0x12345678`` respectively will appear on
the wire as ``05 78 56 34 12``.
Variable Arrays
---------------
Unlike c, length arrays can be used anywhere in structures and will be inline in
the protocol. Furthermore the length may be described using an earlier item in
the structure.
::
struct blob {
u32le size;
u8 data[size];
u32le checksum;
}
This structure is encoded as a 32 bit size, followed by ``size`` data bytes,
then a 32 bit checksum.
Primitive Aliases
-----------------
These types are just aliases for primitive types.
::
// From /src/include/types.h
typedef u32le epoch_t;
typedef u32le ceph_seq_t;
typedef u64le ceph_tid_t;
typedef u64le version_t;
Structures
==========
These are the way structures are encoded. Note that these structures don't
actually exist in the source but are the way that different types are encoded.
Optional
--------
Optionals are represented as a presence byte, followed by the item if it exists.
::
struct ceph_optional<T> {
u8 present;
T element[present? 1 : 0]; // Only if present is non-zero.
}
Optionals are used to encode ``boost::optional`` and, since introducing
C++17 to Ceph, ``std::optional``.
Pair
----
Pairs are simply the first item followed by the second.
::
struct ceph_pair<A,B> {
A a;
B b;
}
Pairs are used to encode ``std::pair``.
Triple
------
Triples are simply the tree elements one after another.
::
struct ceph_triple<A,B,C> {
A a;
B b;
C c;
}
Triples are used to encode ``ceph::triple``.
List
----
Lists are represented as an element count followed by that many elements.
::
struct ceph_list<T> {
u32le length;
T elements[length];
}
.. note::
The size of the elements in the list are not necessarily uniform.
Lists are used to encode ``std::list``, ``std::vector``, ``std::deque``,
``std::set`` and ``ceph::unordered_set``.
Blob
----
A Blob is simply a list of bytes.
::
struct ceph_string {
ceph_list<u8>;
}
// AKA
struct ceph_string {
u32le size;
u8 data[size];
}
Blobs are used to encode ``std::string``, ``const char *`` and ``bufferlist``.
.. note::
The content of a Blob is arbitrary binary data.
Map
---
Maps are a list of pairs.
::
struct ceph_map<K,V> {
ceph_list<ceph_pair<K,V>>;
}
// AKA
struct ceph_map<K,V> {
u32le length;
ceph_pair<K,V> entries[length];
}
Maps are used to encode ``std::map``, ``std::multimap`` and
``ceph::unordered_map``.
Complex Types
=============
These aren't hard to find in the source but the common ones are listed here for
convenience.
utime_t
-------
::
// From /src/include/utime.h
struct utime_t {
u32le tv_sec; // Seconds since epoch.
u32le tv_nsec; // Nanoseconds since the last second.
}
ceph_entity_name
----------------
::
// From /src/include/msgr.h
struct ceph_entity_name {
u8 type; // CEPH_ENTITY_TYPE_*
u64le num;
}
// CEPH_ENTITY_TYPE_* defined in /src/include/msgr.h
.. vi: textwidth=80 noexpandtab
|