aboutsummaryrefslogtreecommitdiff
path: root/thirdparty/tourist/trace/src/preamble.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2026-04-23 18:16:57 +0200
committerStefan Boberg <[email protected]>2026-04-23 18:16:57 +0200
commit0232b991cd7d8e3a2114ea30e4591dd3e7b65c36 (patch)
tree94730e7594fd09ae1fa820391ce311f6daf13905 /thirdparty/tourist/trace/src/preamble.cpp
parentFix forward declaration order for s_GotSigWinch and SigWinchHandler (diff)
parenttrace: declare Region event name fields as AnsiString (#1012) (diff)
downloadarchived-zen-sb/zen-help.tar.xz
archived-zen-sb/zen-help.zip
Merge branch 'main' into sb/zen-helpsb/zen-help
- Combine HelpCommand (this branch) with HistoryCommand (main) in zen CLI dispatcher - Keep filter-aware TuiPickOne rewrite; adopt main's ASCII arrow glyphs in doc comment
Diffstat (limited to 'thirdparty/tourist/trace/src/preamble.cpp')
-rw-r--r--thirdparty/tourist/trace/src/preamble.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/thirdparty/tourist/trace/src/preamble.cpp b/thirdparty/tourist/trace/src/preamble.cpp
new file mode 100644
index 000000000..7b54dbc8e
--- /dev/null
+++ b/thirdparty/tourist/trace/src/preamble.cpp
@@ -0,0 +1,55 @@
+#include <foundation/types.h>
+
+#include <trace/detail/exceptions.h>
+#include <trace/detail/preamble.h>
+#include <trace/detail/protocol.h>
+#include <trace/detail/transport.h>
+
+//------------------------------------------------------------------------------
+Preamble::Preamble(DataSource& source, Allocator& allocator)
+: _stream(source, allocator)
+{
+}
+
+//------------------------------------------------------------------------------
+Transport Preamble::get_transport()
+{
+ if (!_parsed)
+ parse_header();
+
+ return Transport(std::move(_stream));
+}
+
+//------------------------------------------------------------------------------
+Protocol Preamble::get_protocol()
+{
+ if (!_parsed)
+ parse_header();
+
+ return Protocol(_protocol_version);
+}
+
+//------------------------------------------------------------------------------
+void Preamble::parse_header()
+{
+ // magic
+ uint32 magic = _stream.read<uint32>();
+ if (magic != 'TRC2')
+ throw Exception::StreamError("Unexpected magic value", 0, magic);
+
+ // meta
+ uint32 meta_size = _stream.read<uint16>();
+ _stream.read(meta_size);
+
+ // transport
+ _transport_version = _stream.read<uint8>();
+ if (_transport_version != 4)
+ throw Exception::StreamError("Unexpected transport version", 0, _transport_version);
+
+ // protocol
+ _protocol_version = _stream.read<uint8>();
+ if (_protocol_version != 6 && _protocol_version != 7)
+ throw Exception::StreamError("Unexpected protocol version", 0, _protocol_version);
+
+ _parsed = true;
+}