-
Notifications
You must be signed in to change notification settings - Fork 99
/
mcap.ksy
443 lines (415 loc) · 10.2 KB
/
mcap.ksy
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
# This Kaitai Struct definition describes the MCAP binary file format. It can be used with tools
# like the web IDE (https://ide.kaitai.io/) or CLI visualizer
# (https://github.com/kaitai-io/kaitai_struct_visualizer) to parse and visualize MCAP files.
meta:
id: mcap
title: MCAP
file-extension: mcap
license: MIT
endian: le
doc: |
MCAP is a modular container format and logging library for pub/sub messages with
arbitrary message serialization. It is primarily intended for use in robotics
applications, and works well under various workloads, resource constraints, and
durability requirements.
Time values (`log_time`, `publish_time`, `create_time`) are represented in
nanoseconds since a user-understood epoch (i.e. Unix epoch, robot boot time,
etc.)
doc-ref: https://github.com/foxglove/mcap/tree/c1cc51d/docs/specification#readme
seq:
- id: header_magic
type: magic
- id: records
type: record
repeat: until
repeat-until: _.op == opcode::footer
- id: footer_magic
type: magic
instances:
footer:
pos: ofs_footer
size-eos: true
type: record
ofs_footer:
value: "_io.size - footer.op._sizeof - footer.len_body._sizeof - sizeof<footer> - sizeof<magic>"
enums:
opcode:
0x01: header
0x02: footer
0x03: schema
0x04: channel
0x05: message
0x06: chunk
0x07: message_index
0x08: chunk_index
0x09: attachment
0x0a: attachment_index
0x0b: statistics
0x0c: metadata
0x0d: metadata_index
0x0e: summary_offset
0x0f: data_end
types:
magic:
seq:
- id: magic
contents: [0x89, "MCAP0\r\n"]
prefixed_str:
seq:
- id: len_str
type: u4
- id: str
type: str
size: len_str
encoding: UTF-8
tuple_str_str:
seq:
- id: key
type: prefixed_str
- id: value
type: prefixed_str
map_str_str:
seq:
- id: len_entries
type: u4
- id: entries
size: len_entries
type: entries
types:
entries:
seq:
- id: entries
type: tuple_str_str
repeat: eos
records:
seq:
- id: records
type: record
repeat: eos
record:
seq:
- id: op
type: u1
enum: opcode
- id: len_body
type: u8
- id: body
size: len_body
type:
switch-on: op
cases:
opcode::header: header
opcode::footer: footer
opcode::schema: schema
opcode::channel: channel
opcode::message: message
opcode::chunk: chunk
opcode::message_index: message_index
opcode::chunk_index: chunk_index
opcode::attachment: attachment
opcode::attachment_index: attachment_index
opcode::statistics: statistics
opcode::metadata: metadata
opcode::metadata_index: metadata_index
opcode::summary_offset: summary_offset
opcode::data_end: data_end
header:
seq:
- id: profile
type: prefixed_str
- id: library
type: prefixed_str
footer:
seq:
- id: ofs_summary_section
-orig-id: summary_start
type: u8
- id: ofs_summary_offset_section
-orig-id: summary_offset_start
type: u8
- id: summary_crc32
-orig-id: summary_crc
type: u4
doc: |
A CRC-32 of all bytes from the start of the Summary section up through and
including the end of the previous field (summary_offset_start) in the footer
record. A value of 0 indicates the CRC-32 is not available.
instances:
summary_section:
io: _root._io
pos: ofs_summary_section
size: "(ofs_summary_offset_section != 0 ? ofs_summary_offset_section : _root.ofs_footer) - ofs_summary_section"
type: records
if: ofs_summary_section != 0
summary_offset_section:
io: _root._io
pos: ofs_summary_offset_section
size: "_root.ofs_footer - ofs_summary_offset_section"
type: records
if: ofs_summary_offset_section != 0
ofs_summary_crc32_input:
value: "ofs_summary_section != 0 ? ofs_summary_section : _root.ofs_footer"
summary_crc32_input:
io: _root._io
pos: ofs_summary_crc32_input
size: "_root._io.size - ofs_summary_crc32_input - sizeof<magic> - summary_crc32._sizeof"
schema:
seq:
- id: id
type: u2
- id: name
type: prefixed_str
- id: encoding
type: prefixed_str
- id: len_data
type: u4
- id: data
size: len_data
channel:
seq:
- id: id
type: u2
- id: schema_id
type: u2
- id: topic
type: prefixed_str
- id: message_encoding
type: prefixed_str
- id: metadata
type: map_str_str
message:
seq:
- id: channel_id
type: u2
- id: sequence
type: u4
- id: log_time
type: u8
- id: publish_time
type: u8
- id: data
size-eos: true
chunk:
seq:
- id: message_start_time
type: u8
- id: message_end_time
type: u8
- id: uncompressed_size
type: u8
- id: uncompressed_crc32
-orig-id: uncompressed_crc
type: u4
doc: |
CRC-32 checksum of uncompressed `records` field. A value of zero indicates that
CRC validation should not be performed.
- id: compression
type: prefixed_str
- id: len_records
type: u8
- id: records
size: len_records
type:
switch-on: compression.str
cases:
'""': records
message_index:
seq:
- id: channel_id
type: u2
- id: len_records
type: u4
- id: records
size: len_records
type: message_index_entries
types:
message_index_entry:
seq:
- id: log_time
type: u8
- id: offset
type: u8
message_index_entries:
seq:
- id: entries
type: message_index_entry
repeat: eos
chunk_index:
seq:
- id: message_start_time
type: u8
- id: message_end_time
type: u8
- id: ofs_chunk
-orig-id: chunk_start_offset
type: u8
- id: len_chunk
-orig-id: chunk_length
type: u8
- id: len_message_index_offsets
type: u4
- id: message_index_offsets
size: len_message_index_offsets
type: message_index_offsets
- id: message_index_length
type: u8
- id: compression
type: prefixed_str
- id: compressed_size
type: u8
- id: uncompressed_size
type: u8
instances:
chunk:
io: _root._io
pos: ofs_chunk
size: len_chunk
type: record
types:
message_index_offset:
seq:
- id: channel_id
type: u2
- id: offset
type: u8
message_index_offsets:
seq:
- id: entries
type: message_index_offset
repeat: eos
attachment:
seq:
- id: log_time
type: u8
- id: create_time
type: u8
- id: name
type: prefixed_str
- id: media_type
type: prefixed_str
- id: len_data
type: u8
- id: data
size: len_data
# Trigger _io.pos computation: https://github.com/kaitai-io/kaitai_struct/issues/721#issuecomment-623011059
- id: invoke_crc32_input_end
size: 0
if: crc32_input_end >= 0
- id: crc32
-orig-id: crc
type: u4
doc: |
CRC-32 checksum of preceding fields in the record. A value of zero indicates that
CRC validation should not be performed.
instances:
crc32_input_end:
value: _io.pos
crc32_input:
pos: 0
size: crc32_input_end
attachment_index:
seq:
- id: ofs_attachment
-orig-id: offset
type: u8
- id: len_attachment
-orig-id: length
type: u8
- id: log_time
type: u8
- id: create_time
type: u8
- id: data_size
type: u8
- id: name
type: prefixed_str
- id: media_type
type: prefixed_str
instances:
attachment:
io: _root._io
pos: ofs_attachment
size: len_attachment
type: record
statistics:
seq:
- id: message_count
type: u8
- id: schema_count
type: u2
- id: channel_count
type: u4
- id: attachment_count
type: u4
- id: metadata_count
type: u4
- id: chunk_count
type: u4
- id: message_start_time
type: u8
- id: message_end_time
type: u8
- id: len_channel_message_counts
type: u4
- id: channel_message_counts
size: len_channel_message_counts
type: channel_message_counts
types:
channel_message_counts:
seq:
- id: entries
type: channel_message_count
repeat: eos
channel_message_count:
seq:
- id: channel_id
type: u2
- id: message_count
type: u8
metadata:
seq:
- id: name
type: prefixed_str
- id: metadata
type: map_str_str
metadata_index:
seq:
- id: ofs_metadata
-orig-id: offset
type: u8
- id: len_metadata
-orig-id: length
type: u8
- id: name
type: prefixed_str
instances:
metadata:
io: _root._io
pos: ofs_metadata
size: len_metadata
type: record
summary_offset:
seq:
- id: group_opcode
type: u1
enum: opcode
- id: ofs_group
-orig-id: group_start
type: u8
- id: len_group
-orig-id: group_length
type: u8
instances:
group:
io: _root._io
pos: ofs_group
size: len_group
type: records
data_end:
seq:
- id: data_section_crc32
-orig-id: data_section_crc
type: u4
doc: |
CRC-32 of all bytes in the data section. A value of 0 indicates the CRC-32 is not
available.