The entries are used to synchronize the state of services instances and the Publish/-Subscribe handling.
This page hosts a formal specification of AUTOSAR SOME/IP Service Discovery Entries 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_sd_entries_t data(&ks);
After that, one can get various attributes from the structure by invoking getter methods like:
data.entries() // => get entries
#ifndef SOME_IP_SD_ENTRIES_H_
#define SOME_IP_SD_ENTRIES_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 <vector>
#if KAITAI_STRUCT_VERSION < 9000L
#error "Incompatible Kaitai Struct C++/STL API: version 0.9 or later is required"
#endif
/**
* The entries are used to synchronize the state of services instances and the
* Publish/-Subscribe handling.
* \sa https://www.autosar.org/fileadmin/standards/foundation/19-11/AUTOSAR_PRS_SOMEIPServiceDiscoveryProtocol.pdf
* - section 4.1.2.3 Entry Format
*/
class some_ip_sd_entries_t : public kaitai::kstruct {
public:
class sd_entry_t;
some_ip_sd_entries_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent = 0, some_ip_sd_entries_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~some_ip_sd_entries_t();
class sd_entry_t : public kaitai::kstruct {
public:
class sd_entry_header_t;
class sd_service_entry_t;
class sd_eventgroup_entry_t;
enum entry_types_t {
ENTRY_TYPES_FIND = 0,
ENTRY_TYPES_OFFER = 1,
ENTRY_TYPES_SUBSCRIBE = 6,
ENTRY_TYPES_SUBSCRIBE_ACK = 7
};
sd_entry_t(kaitai::kstream* p__io, some_ip_sd_entries_t* p__parent = 0, some_ip_sd_entries_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~sd_entry_t();
class sd_entry_header_t : public kaitai::kstruct {
public:
sd_entry_header_t(kaitai::kstream* p__io, some_ip_sd_entries_t::sd_entry_t* p__parent = 0, some_ip_sd_entries_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~sd_entry_header_t();
private:
entry_types_t m_type;
uint8_t m_index_first_options;
uint8_t m_index_second_options;
uint64_t m_number_first_options;
uint64_t m_number_second_options;
uint16_t m_service_id;
uint16_t m_instance_id;
uint8_t m_major_version;
uint64_t m_ttl;
some_ip_sd_entries_t* m__root;
some_ip_sd_entries_t::sd_entry_t* m__parent;
public:
entry_types_t type() const { return m_type; }
uint8_t index_first_options() const { return m_index_first_options; }
uint8_t index_second_options() const { return m_index_second_options; }
uint64_t number_first_options() const { return m_number_first_options; }
uint64_t number_second_options() const { return m_number_second_options; }
uint16_t service_id() const { return m_service_id; }
uint16_t instance_id() const { return m_instance_id; }
uint8_t major_version() const { return m_major_version; }
uint64_t ttl() const { return m_ttl; }
some_ip_sd_entries_t* _root() const { return m__root; }
some_ip_sd_entries_t::sd_entry_t* _parent() const { return m__parent; }
};
class sd_service_entry_t : public kaitai::kstruct {
public:
sd_service_entry_t(kaitai::kstream* p__io, some_ip_sd_entries_t::sd_entry_t* p__parent = 0, some_ip_sd_entries_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~sd_service_entry_t();
private:
uint32_t m_minor_version;
some_ip_sd_entries_t* m__root;
some_ip_sd_entries_t::sd_entry_t* m__parent;
public:
uint32_t minor_version() const { return m_minor_version; }
some_ip_sd_entries_t* _root() const { return m__root; }
some_ip_sd_entries_t::sd_entry_t* _parent() const { return m__parent; }
};
class sd_eventgroup_entry_t : public kaitai::kstruct {
public:
sd_eventgroup_entry_t(kaitai::kstream* p__io, some_ip_sd_entries_t::sd_entry_t* p__parent = 0, some_ip_sd_entries_t* p__root = 0);
private:
void _read();
void _clean_up();
public:
~sd_eventgroup_entry_t();
private:
uint8_t m_reserved;
bool m_initial_data_requested;
uint64_t m_reserved2;
uint64_t m_counter;
uint16_t m_event_group_id;
some_ip_sd_entries_t* m__root;
some_ip_sd_entries_t::sd_entry_t* m__parent;
public:
uint8_t reserved() const { return m_reserved; }
bool initial_data_requested() const { return m_initial_data_requested; }
uint64_t reserved2() const { return m_reserved2; }
uint64_t counter() const { return m_counter; }
uint16_t event_group_id() const { return m_event_group_id; }
some_ip_sd_entries_t* _root() const { return m__root; }
some_ip_sd_entries_t::sd_entry_t* _parent() const { return m__parent; }
};
private:
sd_entry_header_t* m_header;
kaitai::kstruct* m_content;
bool n_content;
public:
bool _is_null_content() { content(); return n_content; };
private:
some_ip_sd_entries_t* m__root;
some_ip_sd_entries_t* m__parent;
public:
sd_entry_header_t* header() const { return m_header; }
kaitai::kstruct* content() const { return m_content; }
some_ip_sd_entries_t* _root() const { return m__root; }
some_ip_sd_entries_t* _parent() const { return m__parent; }
};
private:
std::vector<sd_entry_t*>* m_entries;
some_ip_sd_entries_t* m__root;
kaitai::kstruct* m__parent;
public:
std::vector<sd_entry_t*>* entries() const { return m_entries; }
some_ip_sd_entries_t* _root() const { return m__root; }
kaitai::kstruct* _parent() const { return m__parent; }
};
#endif // SOME_IP_SD_ENTRIES_H_
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild
#include "some_ip_sd_entries.h"
some_ip_sd_entries_t::some_ip_sd_entries_t(kaitai::kstream* p__io, kaitai::kstruct* p__parent, some_ip_sd_entries_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = this;
m_entries = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void some_ip_sd_entries_t::_read() {
m_entries = new std::vector<sd_entry_t*>();
{
int i = 0;
while (!m__io->is_eof()) {
m_entries->push_back(new sd_entry_t(m__io, this, m__root));
i++;
}
}
}
some_ip_sd_entries_t::~some_ip_sd_entries_t() {
_clean_up();
}
void some_ip_sd_entries_t::_clean_up() {
if (m_entries) {
for (std::vector<sd_entry_t*>::iterator it = m_entries->begin(); it != m_entries->end(); ++it) {
delete *it;
}
delete m_entries; m_entries = 0;
}
}
some_ip_sd_entries_t::sd_entry_t::sd_entry_t(kaitai::kstream* p__io, some_ip_sd_entries_t* p__parent, some_ip_sd_entries_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
m_header = 0;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void some_ip_sd_entries_t::sd_entry_t::_read() {
m_header = new sd_entry_header_t(m__io, this, m__root);
n_content = true;
switch (header()->type()) {
case some_ip_sd_entries_t::sd_entry_t::ENTRY_TYPES_FIND: {
n_content = false;
m_content = new sd_service_entry_t(m__io, this, m__root);
break;
}
case some_ip_sd_entries_t::sd_entry_t::ENTRY_TYPES_OFFER: {
n_content = false;
m_content = new sd_service_entry_t(m__io, this, m__root);
break;
}
case some_ip_sd_entries_t::sd_entry_t::ENTRY_TYPES_SUBSCRIBE: {
n_content = false;
m_content = new sd_eventgroup_entry_t(m__io, this, m__root);
break;
}
case some_ip_sd_entries_t::sd_entry_t::ENTRY_TYPES_SUBSCRIBE_ACK: {
n_content = false;
m_content = new sd_eventgroup_entry_t(m__io, this, m__root);
break;
}
}
}
some_ip_sd_entries_t::sd_entry_t::~sd_entry_t() {
_clean_up();
}
void some_ip_sd_entries_t::sd_entry_t::_clean_up() {
if (m_header) {
delete m_header; m_header = 0;
}
if (!n_content) {
if (m_content) {
delete m_content; m_content = 0;
}
}
}
some_ip_sd_entries_t::sd_entry_t::sd_entry_header_t::sd_entry_header_t(kaitai::kstream* p__io, some_ip_sd_entries_t::sd_entry_t* p__parent, some_ip_sd_entries_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void some_ip_sd_entries_t::sd_entry_t::sd_entry_header_t::_read() {
m_type = static_cast<some_ip_sd_entries_t::sd_entry_t::entry_types_t>(m__io->read_u1());
m_index_first_options = m__io->read_u1();
m_index_second_options = m__io->read_u1();
m_number_first_options = m__io->read_bits_int_be(4);
m_number_second_options = m__io->read_bits_int_be(4);
m__io->align_to_byte();
m_service_id = m__io->read_u2be();
m_instance_id = m__io->read_u2be();
m_major_version = m__io->read_u1();
m_ttl = m__io->read_bits_int_be(24);
}
some_ip_sd_entries_t::sd_entry_t::sd_entry_header_t::~sd_entry_header_t() {
_clean_up();
}
void some_ip_sd_entries_t::sd_entry_t::sd_entry_header_t::_clean_up() {
}
some_ip_sd_entries_t::sd_entry_t::sd_service_entry_t::sd_service_entry_t(kaitai::kstream* p__io, some_ip_sd_entries_t::sd_entry_t* p__parent, some_ip_sd_entries_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void some_ip_sd_entries_t::sd_entry_t::sd_service_entry_t::_read() {
m_minor_version = m__io->read_u4be();
}
some_ip_sd_entries_t::sd_entry_t::sd_service_entry_t::~sd_service_entry_t() {
_clean_up();
}
void some_ip_sd_entries_t::sd_entry_t::sd_service_entry_t::_clean_up() {
}
some_ip_sd_entries_t::sd_entry_t::sd_eventgroup_entry_t::sd_eventgroup_entry_t(kaitai::kstream* p__io, some_ip_sd_entries_t::sd_entry_t* p__parent, some_ip_sd_entries_t* p__root) : kaitai::kstruct(p__io) {
m__parent = p__parent;
m__root = p__root;
try {
_read();
} catch(...) {
_clean_up();
throw;
}
}
void some_ip_sd_entries_t::sd_entry_t::sd_eventgroup_entry_t::_read() {
m_reserved = m__io->read_u1();
m_initial_data_requested = m__io->read_bits_int_be(1);
m_reserved2 = m__io->read_bits_int_be(3);
m_counter = m__io->read_bits_int_be(4);
m__io->align_to_byte();
m_event_group_id = m__io->read_u2be();
}
some_ip_sd_entries_t::sd_entry_t::sd_eventgroup_entry_t::~sd_eventgroup_entry_t() {
_clean_up();
}
void some_ip_sd_entries_t::sd_entry_t::sd_eventgroup_entry_t::_clean_up() {
}