Remove dummy 0, store the crc32 there

This commit is contained in:
King_DuckZ 2022-05-24 16:07:43 +02:00
parent e8db08931a
commit b0422b73d6
2 changed files with 6 additions and 3 deletions

View file

@ -18,6 +18,7 @@
#pragma once #pragma once
#include "string_bt.hpp" #include "string_bt.hpp"
#include "crc32.hpp"
#include <string_view> #include <string_view>
#include <cstdint> #include <cstdint>
#include <cassert> #include <cassert>
@ -131,11 +132,12 @@ namespace wren {
template <dhandy::bt::string S1, dhandy::bt::string S2> template <dhandy::bt::string S1, dhandy::bt::string S2>
constexpr ModuleAndName make_module_and_name() { constexpr ModuleAndName make_module_and_name() {
using dhandy::bt::string; using dhandy::bt::string;
using StaticStorage = detail::ModuleAndNameStaticStorage<S1 + string("\0") + S2>;
constexpr const char* data = detail::ModuleAndNameStaticStorage<S1 + string("\0") + S2>::value.data(); constexpr const char* data = StaticStorage::value.data();
constexpr std::uint16_t s1_len = static_cast<std::uint16_t>(S1.size()); constexpr std::uint16_t s1_len = static_cast<std::uint16_t>(S1.size());
constexpr std::uint16_t s2_len = static_cast<std::uint16_t>(S2.size()); constexpr std::uint16_t s2_len = static_cast<std::uint16_t>(S2.size());
constexpr std::uint32_t hash = 0; //not implemented yet constexpr std::uint32_t hash = crc32c(data, StaticStorage::value.size());
return ModuleAndName{data, hash, s1_len, s2_len}; return ModuleAndName{data, hash, s1_len, s2_len};
} }

View file

@ -16,6 +16,7 @@
*/ */
#include "wrenpp/class_manager.hpp" #include "wrenpp/class_manager.hpp"
#include "wrenpp/detail/crc32.hpp"
#include <cassert> #include <cassert>
namespace wren { namespace wren {
@ -40,7 +41,7 @@ namespace wren {
ClassNameOwning::operator ModuleAndName() const { ClassNameOwning::operator ModuleAndName() const {
return ModuleAndName{ return ModuleAndName{
this->raw_buffer(), this->raw_buffer(),
0, //TODO: replace with hash crc32c(this->raw_buffer(), this->raw_buffer_size()),
this->module_name().size(), this->module_name().size(),
this->class_name().size() this->class_name().size()
}; };