def _make_ctf_1_metadata(payload_fc: str):
- payload_fc = payload_fc.strip()
-
if "@" in payload_fc:
payload_fc = payload_fc.replace("@", "root")
else:
).substitute(payload_fc=payload_fc)
+def _make_ctf_2_metadata(payload_fc: str):
+ return string.Template(
+ """\
+\x1e{
+ "type": "preamble",
+ "version": "2"
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u8le",
+ "field-class": {
+ "type": "fixed-length-unsigned-integer",
+ "length": 8,
+ "byte-order": "little-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u16le",
+ "field-class": {
+ "type": "fixed-length-unsigned-integer",
+ "length": 16,
+ "byte-order": "little-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u32le",
+ "field-class": {
+ "type": "fixed-length-unsigned-integer",
+ "length": 32,
+ "byte-order": "little-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u64le",
+ "field-class": {
+ "type": "fixed-length-unsigned-integer",
+ "length": 64,
+ "byte-order": "little-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u8",
+ "field-class": "u8le"
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u16",
+ "field-class": "u16le"
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u32",
+ "field-class": "u32le"
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u64",
+ "field-class": "u64le"
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u8be",
+ "field-class": {
+ "type": "fixed-length-unsigned-integer",
+ "length": 8,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u16be",
+ "field-class": {
+ "type": "fixed-length-unsigned-integer",
+ "length": 16,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u32be",
+ "field-class": {
+ "type": "fixed-length-unsigned-integer",
+ "length": 32,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u64be",
+ "field-class": {
+ "type": "fixed-length-unsigned-integer",
+ "length": 64,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "i8le",
+ "field-class": {
+ "type": "fixed-length-signed-integer",
+ "length": 8,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "i16le",
+ "field-class": {
+ "type": "fixed-length-signed-integer",
+ "length": 16,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "i32le",
+ "field-class": {
+ "type": "fixed-length-signed-integer",
+ "length": 32,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "i64le",
+ "field-class": {
+ "type": "fixed-length-signed-integer",
+ "length": 64,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "i8be",
+ "field-class": {
+ "type": "fixed-length-signed-integer",
+ "length": 8,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "i16be",
+ "field-class": {
+ "type": "fixed-length-signed-integer",
+ "length": 16,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "i32be",
+ "field-class": {
+ "type": "fixed-length-signed-integer",
+ "length": 32,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "u64be",
+ "field-class": {
+ "type": "fixed-length-signed-integer",
+ "length": 64,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "flt32le",
+ "field-class": {
+ "type": "fixed-length-floating-point-number",
+ "length": 32,
+ "byte-order": "little-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "flt64le",
+ "field-class": {
+ "type": "fixed-length-floating-point-number",
+ "length": 64,
+ "byte-order": "little-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "flt32",
+ "field-class": "flt32le"
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "flt64",
+ "field-class": "flt64le"
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "flt32be",
+ "field-class": {
+ "type": "fixed-length-floating-point-number",
+ "length": 32,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "flt64be",
+ "field-class": {
+ "type": "fixed-length-floating-point-number",
+ "length": 64,
+ "byte-order": "big-endian",
+ "alignment": 8
+ }
+}
+\x1e{
+ "type": "field-class-alias",
+ "name": "nt-str",
+ "field-class": {
+ "type": "null-terminated-string"
+ }
+}
+\x1e{
+ "type": "data-stream-class"
+}
+\x1e{
+ "type": "event-record-class",
+ "payload-field-class": {
+ "type": "structure",
+ "member-field-classes": [
+ {
+ "name": "root",
+ "field-class": ${payload_fc}
+ }
+ ]
+ }
+}
+"""
+ ).substitute(payload_fc=payload_fc)
+
+
+def _make_ctf_metadata(payload_fc: str):
+ if payload_fc.startswith("{") or payload_fc.startswith('"'):
+ # CTF 2
+ return _make_ctf_2_metadata(payload_fc)
+ else:
+ # Assume CTF 1.8
+ return _make_ctf_1_metadata(payload_fc)
+
+
def _make_ctf_1_data(normand_text: str):
- # Default to little-endian because that's also the TSDL default in
- # _make_ctf_1_metadata() above.
+ # Default to little-endian because that's also the default in
+ # _make_ctf_1_metadata() and _make_ctf_2_metadata() above.
return normand.parse("!le\n" + normand_text).data
parts = moultipart.parse(f)
with open(metadata_path, "w") as f:
- f.write(_make_ctf_1_metadata(parts[0].content))
+ f.write(_make_ctf_metadata(parts[0].content.strip()))
with open(data_path, "wb") as f:
f.write(_make_ctf_1_data(parts[1].content))