diff options
Diffstat (limited to 'thirdparty/tourist/trace/src/preamble.cpp')
| -rw-r--r-- | thirdparty/tourist/trace/src/preamble.cpp | 55 |
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; +} |