//
// Created by Dan Crosby on 10/23/22.
//

#ifndef EAGLE0_ACTIONRESULTFLATBUFFERHELPERS_HPP
#define EAGLE0_ACTIONRESULTFLATBUFFERHELPERS_HPP

#include <string>

#include "src/main/flatbuffer/net/eagle0/shardok/storage/unit.hpp"
#include "src/main/protobuf/net/eagle0/shardok/storage/action_result.pb.h"

namespace shardok {

using std::string;
using ActionResult = net::eagle0::shardok::storage::ActionResult;
using ResolvedUnit = net::eagle0::shardok::storage::ResolvedUnit;
using Unit = net::eagle0::shardok::storage::fb::Unit;

static inline void AddChangedUnit(ActionResult& result, const Unit& unit) {
    result.add_changed_units_fb(&unit, sizeof(Unit));
}

static inline void AddUnitToResolved(ResolvedUnit& resolvedUnit, const Unit& unit) {
    *resolvedUnit.mutable_unit_bytes() = string((char*)&unit, sizeof(Unit));
}

}  // namespace shardok

#endif  // EAGLE0_ACTIONRESULTFLATBUFFERHELPERS_HPP
