Instantly share code, notes, and snippets.
berkus/nav_parent.cpp Secret
Created
August 4, 2017 21:51
-
Star
(0)
0
You must be signed in to star a gist -
Fork
(0)
0
You must be signed in to fork a gist
-
Save berkus/9e656fcc2631a13614f19bc85746365d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild | |
#include "nav_parent.h" | |
void nav_parent_t::_read() { | |
m_header = std::make_unique<header_obj_t>(m__io, this, m__root); | |
m_index = std::make_unique<index_obj_t>(m__io, this, m__root); | |
} | |
void nav_parent_t::header_obj_t::_read() { | |
m_qty_entries = m__io->read_u4le(); | |
m_filename_len = m__io->read_u4le(); | |
} | |
void nav_parent_t::index_obj_t::_read() { | |
m_magic = m__io->read_bytes(4); | |
int l_entries = _parent()->header()->qty_entries(); | |
m_entries = std::make_unique<std::vector<entry_uptr_t>>(); | |
m_entries->reserve(l_entries); | |
for (int i = 0; i < l_entries; i++) { | |
m_entries->push_back(std::make_unique<entry_t>(m__io, this, m__root)); | |
} | |
} | |
void nav_parent_t::entry_t::_read() { | |
m_filename = kaitai::kstream::bytes_to_str(m__io->read_bytes(_parent()->_parent()->header()->filename_len()), "UTF-8"s); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild | |
#include <kaitai/kaitaistruct.h> | |
#include <kaitai/kaitaistream.h> | |
#include <cstdint> | |
#include <vector> | |
#if KAITAI_STRUCT_VERSION < 7000L | |
#error "Incompatible Kaitai Struct C++/STL API: version 0.7 or later is required" | |
#endif | |
class nav_parent_t : public kaitai::kstruct { | |
public: | |
class header_obj_t; | |
class index_obj_t; | |
class entry_t; | |
nav_parent_t(std::shared_ptr<kaitai::kstream> p_io, std::shared_ptr<kaitai::kstruct> p_parent = nullptr, std::shared_ptr<nav_parent_t> p_root = nullptr) | |
: kaitai::kstruct(p_io) | |
, m__parent(p_parent) | |
{ | |
m__root = this; // NB: Cannot use shared_from_this() in constructor... | |
_read(); | |
} | |
~nav_parent_t() = default; | |
void _read(); | |
class header_obj_t : public kaitai::kstruct { | |
public: | |
header_obj_t(std::shared_ptr<kaitai::kstream> p_io, std::shared_ptr<nav_parent_t> p_parent = nullptr, std::shared_ptr<nav_parent_t> p_root = nullptr) | |
: kaitai::kstruct(p_io) | |
, m__root(p_root) | |
, m__parent(p_parent) | |
{ | |
_read(); | |
} | |
~header_obj_t() = default; | |
void _read(); | |
private: | |
std::uint32_t m_qty_entries; | |
std::uint32_t m_filename_len; | |
std::weak_ptr<nav_parent_t> m__root; | |
std::weak_ptr<nav_parent_t> m__parent; | |
public: | |
std::uint32_t qty_entries() const { return m_qty_entries; } | |
std::uint32_t filename_len() const { return m_filename_len; } | |
nav_parent_t* _root() const { return m__root.lock(); } | |
nav_parent_t* _parent() const { return m__parent.lock(); } | |
}; | |
class index_obj_t : public kaitai::kstruct { | |
public: | |
index_obj_t(std::shared_ptr<kaitai::kstream> p_io, std::shared_ptr<nav_parent_t> p_parent = nullptr, std::shared_ptr<nav_parent_t> p_root = nullptr) | |
: kaitai::kstruct(p_io) | |
, m__root(p_root) | |
, m__parent(p_parent) | |
{ | |
_read(); | |
} | |
~index_obj_t() = default; | |
void _read(); | |
private: | |
std::string m_magic; | |
std::unique_ptr<std::vector<entry_uptr_t>> m_entries; | |
std::weak_ptr<nav_parent_t> m__root; | |
std::weak_ptr<nav_parent_t> m__parent; | |
public: | |
std::string magic() const { return m_magic; } | |
std::unique_ptr<std::vector<entry_uptr_t>> entries() const { return m_entries; } | |
nav_parent_t* _root() const { return m__root.lock(); } | |
nav_parent_t* _parent() const { return m__parent.lock(); } | |
}; | |
class entry_t : public kaitai::kstruct { | |
public: | |
entry_t(std::shared_ptr<kaitai::kstream> p_io, std::shared_ptr<nav_parent_t::index_obj_t> p_parent = nullptr, std::shared_ptr<nav_parent_t> p_root = nullptr) | |
: kaitai::kstruct(p_io) | |
, m__root(p_root) | |
, m__parent(p_parent) | |
{ | |
_read(); | |
} | |
~entry_t() = default; | |
void _read(); | |
private: | |
std::string m_filename; | |
std::weak_ptr<nav_parent_t> m__root; | |
std::weak_ptr<nav_parent_t::index_obj_t> m__parent; | |
public: | |
std::string filename() const { return m_filename; } | |
nav_parent_t* _root() const { return m__root.lock(); } | |
nav_parent_t::index_obj_t* _parent() const { return m__parent.lock(); } | |
}; | |
private: | |
std::unique_ptr<header_obj_t> m_header; | |
std::unique_ptr<index_obj_t> m_index; | |
nav_parent_t* m__root; | |
kaitai::kstruct* m__parent; | |
public: | |
header_obj_t* header() const { return m_header.get(); } | |
index_obj_t* index() const { return m_index.get(); } | |
nav_parent_t* _root() const { return m__root; } | |
kaitai::kstruct* _parent() const { return m__parent; } | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment