#pragma once

// @generated by thrift-lite.py; do not edit.

#include <cstddef>
#include <cstdint>
#include <type_traits>
#include <utility>

#include <dwarfs/thrift_lite/detail/protocol_helpers.h>
#include <dwarfs/thrift_lite/detail/protocol_methods.h>

namespace apache::thrift::frozen::schema {

inline void Field::write(::dwarfs::thrift_lite::protocol_writer_type auto& w) const {
  auto const& opts = w.options();

  w.write_struct_begin("Field");

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, layoutId_)) {
    w.write_field_begin("layoutId", ::dwarfs::thrift_lite::ttype::i16_t, 1);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(layoutId_)>>::write(w, layoutId_);
    w.write_field_end();
  }

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, offset_)) {
    w.write_field_begin("offset", ::dwarfs::thrift_lite::ttype::i16_t, 2);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(offset_)>>::write(w, offset_);
    w.write_field_end();
  }

  w.write_field_stop();
  w.write_struct_end();
}

inline void Field::read(::dwarfs::thrift_lite::protocol_reader_type auto& r) {
  layoutId_ = {};
  offset_ = {};

  r.read_struct_begin();

  for (;;) {
    auto field_type = ::dwarfs::thrift_lite::ttype{};
    auto field_id = std::int16_t{};

    r.read_field_begin(field_type, field_id);

    if (field_type == ::dwarfs::thrift_lite::ttype::stop_t) {
      break;
    }

    bool skip = true;

    switch (field_id) {
      case 1:
        if (field_type == ::dwarfs::thrift_lite::ttype::i16_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(layoutId_)>>::read(r, layoutId_);
          skip = false;
        }
        break;

      case 2:
        if (field_type == ::dwarfs::thrift_lite::ttype::i16_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(offset_)>>::read(r, offset_);
          skip = false;
        }
        break;

  default:
    break;
}
    if (skip) {
      r.skip(field_type);
    }

    r.read_field_end();
  }

  r.read_struct_end();
}

inline void Layout::write(::dwarfs::thrift_lite::protocol_writer_type auto& w) const {
  auto const& opts = w.options();

  w.write_struct_begin("Layout");

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, size_)) {
    w.write_field_begin("size", ::dwarfs::thrift_lite::ttype::i32_t, 1);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(size_)>>::write(w, size_);
    w.write_field_end();
  }

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, bits_)) {
    w.write_field_begin("bits", ::dwarfs::thrift_lite::ttype::i16_t, 2);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(bits_)>>::write(w, bits_);
    w.write_field_end();
  }

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, fields_)) {
    w.write_field_begin("fields", ::dwarfs::thrift_lite::ttype::map_t, 3);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::map<::dwarfs::thrift_lite::detail::type_class::integral, ::dwarfs::thrift_lite::detail::type_class::structure>, std::remove_cvref_t<decltype(fields_)>>::write(w, fields_);
    w.write_field_end();
  }

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, typeName_)) {
    w.write_field_begin("typeName", ::dwarfs::thrift_lite::ttype::string_t, 4);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::string, std::remove_cvref_t<decltype(typeName_)>>::write(w, typeName_);
    w.write_field_end();
  }

  w.write_field_stop();
  w.write_struct_end();
}

inline void Layout::read(::dwarfs::thrift_lite::protocol_reader_type auto& r) {
  size_ = {};
  bits_ = {};
  fields_ = {};
  typeName_ = {};

  r.read_struct_begin();

  for (;;) {
    auto field_type = ::dwarfs::thrift_lite::ttype{};
    auto field_id = std::int16_t{};

    r.read_field_begin(field_type, field_id);

    if (field_type == ::dwarfs::thrift_lite::ttype::stop_t) {
      break;
    }

    bool skip = true;

    switch (field_id) {
      case 1:
        if (field_type == ::dwarfs::thrift_lite::ttype::i32_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(size_)>>::read(r, size_);
          skip = false;
        }
        break;

      case 2:
        if (field_type == ::dwarfs::thrift_lite::ttype::i16_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(bits_)>>::read(r, bits_);
          skip = false;
        }
        break;

      case 3:
        if (field_type == ::dwarfs::thrift_lite::ttype::map_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::map<::dwarfs::thrift_lite::detail::type_class::integral, ::dwarfs::thrift_lite::detail::type_class::structure>, std::remove_cvref_t<decltype(fields_)>>::read(r, fields_);
          skip = false;
        }
        break;

      case 4:
        if (field_type == ::dwarfs::thrift_lite::ttype::binary_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::string, std::remove_cvref_t<decltype(typeName_)>>::read(r, typeName_);
          skip = false;
        }
        break;

  default:
    break;
}
    if (skip) {
      r.skip(field_type);
    }

    r.read_field_end();
  }

  r.read_struct_end();
}

inline void Schema::write(::dwarfs::thrift_lite::protocol_writer_type auto& w) const {
  auto const& opts = w.options();

  w.write_struct_begin("Schema");

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, relaxTypeChecks_)) {
    w.write_field_begin("relaxTypeChecks", ::dwarfs::thrift_lite::ttype::bool_t, 1);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(relaxTypeChecks_)>>::write(w, relaxTypeChecks_);
    w.write_field_end();
  }

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, layouts_)) {
    w.write_field_begin("layouts", ::dwarfs::thrift_lite::ttype::map_t, 2);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::map<::dwarfs::thrift_lite::detail::type_class::integral, ::dwarfs::thrift_lite::detail::type_class::structure>, std::remove_cvref_t<decltype(layouts_)>>::write(w, layouts_);
    w.write_field_end();
  }

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, rootLayout_)) {
    w.write_field_begin("rootLayout", ::dwarfs::thrift_lite::ttype::i16_t, 3);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(rootLayout_)>>::write(w, rootLayout_);
    w.write_field_end();
  }

  if (::dwarfs::thrift_lite::detail::should_write_regular(opts, fileVersion_)) {
    w.write_field_begin("fileVersion", ::dwarfs::thrift_lite::ttype::i32_t, 4);
    ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(fileVersion_)>>::write(w, fileVersion_);
    w.write_field_end();
  }

  w.write_field_stop();
  w.write_struct_end();
}

inline void Schema::read(::dwarfs::thrift_lite::protocol_reader_type auto& r) {
  fileVersion_ = {};
  relaxTypeChecks_ = {};
  layouts_ = {};
  rootLayout_ = {};

  r.read_struct_begin();

  for (;;) {
    auto field_type = ::dwarfs::thrift_lite::ttype{};
    auto field_id = std::int16_t{};

    r.read_field_begin(field_type, field_id);

    if (field_type == ::dwarfs::thrift_lite::ttype::stop_t) {
      break;
    }

    bool skip = true;

    switch (field_id) {
      case 1:
        if (field_type == ::dwarfs::thrift_lite::ttype::bool_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(relaxTypeChecks_)>>::read(r, relaxTypeChecks_);
          skip = false;
        }
        break;

      case 2:
        if (field_type == ::dwarfs::thrift_lite::ttype::map_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::map<::dwarfs::thrift_lite::detail::type_class::integral, ::dwarfs::thrift_lite::detail::type_class::structure>, std::remove_cvref_t<decltype(layouts_)>>::read(r, layouts_);
          skip = false;
        }
        break;

      case 3:
        if (field_type == ::dwarfs::thrift_lite::ttype::i16_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(rootLayout_)>>::read(r, rootLayout_);
          skip = false;
        }
        break;

      case 4:
        if (field_type == ::dwarfs::thrift_lite::ttype::i32_t) {
          ::dwarfs::thrift_lite::detail::protocol_methods<::dwarfs::thrift_lite::detail::type_class::integral, std::remove_cvref_t<decltype(fileVersion_)>>::read(r, fileVersion_);
          skip = false;
        }
        break;

  default:
    break;
}
    if (skip) {
      r.skip(field_type);
    }

    r.read_field_end();
  }

  r.read_struct_end();
}

} // namespace apache::thrift::frozen::schema

