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++98/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
#ifndef SOME_IP_CONTAINER_H_
#define SOME_IP_CONTAINER_H_
// 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 "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 = 0, some_ip_container_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~some_ip_container_t();
private:
std::vector<some_ip_t*>* m_some_ip_packages;
some_ip_container_t* m__root;
kaitai::kstruct* m__parent;
public:
std::vector<some_ip_t*>* some_ip_packages() const { return m_some_ip_packages; }
some_ip_container_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};
#endif // SOME_IP_CONTAINER_H_
// 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 = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void some_ip_container_t::_read() {
m_some_ip_packages = new std::vector<some_ip_t*>();
{
int i = 0;
while (!m__io->is_eof()) {
m_some_ip_packages->push_back(new some_ip_t(m__io));
i++;
}
}
}
some_ip_container_t::~some_ip_container_t() {
_clean_up();
}
void some_ip_container_t::_clean_up() {
if (m_some_ip_packages) {
for (std::vector<some_ip_t*>::iterator it = m_some_ip_packages->begin(); it != m_some_ip_packages->end(); ++it) {
delete *it;
}
delete m_some_ip_packages; m_some_ip_packages = 0;
}
}