This page hosts a formal specification of AUTOSAR SOME/IP container using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.
All parsing code for C++11/STL generated by Kaitai Struct depends on the C++/STL runtime library. You have to install it before you can parse data.
For C++, the easiest way is to clone the runtime library sources and build them along with your project.
Using Kaitai Struct in C++/STL usually consists of 3 steps.
std::istream
). One can open local file for that, or use existing std::string
or char*
buffer.
#include <fstream>
std::ifstream is("path/to/local/file.bin", std::ifstream::binary);
#include <sstream>
std::istringstream is(str);
#include <sstream>
const char buf[] = { ... };
std::string str(buf, sizeof buf);
std::istringstream is(str);
#include "kaitai/kaitaistream.h"
kaitai::kstream ks(&is);
some_ip_container_t data(&ks);
After that, one can get various attributes from the structure by invoking getter methods like:
data.some_ip_packages() // => get some ip packages
#pragma once
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "kaitai/kaitaistruct.h"
#include <stdint.h>
#include <memory>
#include "some_ip.h"
#include <vector>
#if KAITAI_STRUCT_VERSION < 9000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required"
#endif
class some_ip_t;
class some_ip_container_t : public kaitai::kstruct {
public:
some_ip_container_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = nullptr, some_ip_container_t* p__root = nullptr);
private:
void _read();
void _clean_up();
public:
~some_ip_container_t();
private:
std::unique_ptr<std::vector<std::unique_ptr<some_ip_t>>> m_some_ip_packages;
some_ip_container_t* m__root;
kaitai::kstruct* m__parent;
public:
std::vector<std::unique_ptr<some_ip_t>>* some_ip_packages() const { return m_some_ip_packages.get(); }
some_ip_container_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "some_ip_container.h"
some_ip_container_t::some_ip_container_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, some_ip_container_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_some_ip_packages = nullptr;
_read();
}
void some_ip_container_t::_read() {
m_some_ip_packages = std::unique_ptr<std::vector<std::unique_ptr<some_ip_t>>>(new std::vector<std::unique_ptr<some_ip_t>>());
{
int i = 0;
while (!m__io->is_eof()) {
m_some_ip_packages->push_back(std::move(std::unique_ptr<some_ip_t>(new some_ip_t(m__io))));
i++;
}
}
}
some_ip_container_t::~some_ip_container_t() {
_clean_up();
}
void some_ip_container_t::_clean_up() {
}