Files
MicrOBU/microbu-esp32c5/external/vanetza-idf/vanetza/common/archives.hpp
T
Ashin Walpola 0e9525162d Keep the colleague's microbu-esp32c5 tree in this repository
obu-firmware builds against vanetza-idf from microbu-esp32c5/external, but
that tree was gitignored, so a clone of this repository could not build the
firmware it ships. It is now committed here as ordinary files in its own
folder, microbu-esp32c5/: the colleague's commit cf4b99f plus the V2X2MAP
bridge's signature verification (--trust) used on the bench. Nothing is
fetched from or pushed to the colleague's repository; this repository and
its remotes carry everything. The folder's own .gitignore keeps build output,
downloaded components and private key material out, as it did there; the
committed file set is identical to that repository's tracked files.

The ESP32-C5 is still flashed from obu-firmware/, which only takes
vanetza-idf from microbu-esp32c5/, so the two stay separate folders.
FLASHING.md says how to take a newer version of the colleague's tree (copy
it over the folder, rebuild, test, commit).
2026-09-23 17:46:40 +02:00

93 lines
2.2 KiB
C++

#ifndef ARCHIVES_HPP_TLVURDQK
#define ARCHIVES_HPP_TLVURDQK
#include <vanetza/common/byte_order.hpp>
#include <exception>
#include <istream>
#include <ostream>
#include <streambuf>
namespace vanetza
{
/**
* This is a drop-in replacement for boost::archive::binary_iarchive
*/
class InputArchive
{
public:
using InputStream = std::basic_istream<char>;
using StreamBuffer = std::basic_streambuf<char>;
class Exception : public std::runtime_error {
using std::runtime_error::runtime_error;
};
enum class ErrorCode {
Ok,
IncompleteData,
ExcessiveLength,
ConstraintViolation,
};
InputArchive(InputStream& is);
InputArchive(StreamBuffer& buf);
template<typename T>
InputArchive& operator>>(T& t)
{
static_assert(std::is_integral<T>::value == true, "only integral types are supported");
char* ptr = reinterpret_cast<char*>(&t);
load_binary(ptr, sizeof(T));
return *this;
}
void load_binary(unsigned char* data, std::size_t len);
void load_binary(char* data, std::size_t len);
char peek_byte();
std::size_t remaining_bytes();
bool is_good() const;
ErrorCode error_code() const;
void fail(ErrorCode error_code);
private:
StreamBuffer* m_stream_buffer;
ErrorCode m_error_code = ErrorCode::Ok;
};
/**
* This is a drop-in replacement for boost::archive::binary_oarchive
*/
class OutputArchive
{
public:
using OutputStream = std::basic_ostream<char>;
using StreamBuffer = std::basic_streambuf<char>;
class Exception : public std::runtime_error {
using std::runtime_error::runtime_error;
};
OutputArchive(OutputStream& os);
OutputArchive(StreamBuffer& buf);
template<typename T>
OutputArchive& operator<<(const T& t)
{
static_assert(std::is_integral<T>::value == true, "only integral types are supported");
const char* ptr = reinterpret_cast<const char*>(&t);
save_binary(ptr, sizeof(T));
return *this;
}
void save_binary(const unsigned char* data, std::size_t len);
void save_binary(const char* data, std::size_t len);
private:
StreamBuffer* m_stream_buffer;
};
} // namespace vanetza
#endif /* ARCHIVES_HPP_TLVURDQK */