obu-firmware builds against the vanetza-idf C-ITS library, which until now came from the colleague's microbu-esp32c5 tree beside the repository and was not tracked here, so a clone of this repository could not build the firmware it ships. The library alone is now part of obu-firmware, as obu-firmware/external/vanetza-idf: their external/vanetza-idf at commit cf4b99f, unchanged (9775 files; see its PROVENANCE.md). CMake takes it from there by default; -DVANETZA_IDF_DIR still points the build elsewhere. The rest of the colleague's tree (their own VAM firmware, PKI tooling, station-link Python tools, the V2X2MAP bridge) stays out of this repository and gitignored; nothing is pushed to their repository. NOTES.md, docs/06, TODO.md and the pcap verifier's usage line point at the new location.
93 lines
2.2 KiB
C++
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 */
|
|
|