Files
integration/luprex/cpp/core/invocation.cpp

47 lines
1.4 KiB
C++
Raw Normal View History

#include "wrap-string.hpp"
#include "wrap-map.hpp"
#include "wrap-deque.hpp"
#include "wrap-sstream.hpp"
#include "invocation.hpp"
2024-09-02 21:48:24 -04:00
Invocation::Invocation() : kind_(InvocationKind::INVALID), actor_(0), place_(0) {}
2024-09-02 21:48:24 -04:00
Invocation::Invocation(InvocationKind kind, int64_t actor, int64_t place, std::string_view datapack)
: kind_(kind), actor_(actor), place_(place), datapack_(datapack) {}
2021-11-16 12:20:11 -05:00
void Invocation::serialize(StreamBuffer *sb) const {
2024-09-02 21:48:24 -04:00
sb->write_uint8(int64_t(kind_));
sb->write_int64(actor_);
sb->write_int64(place_);
sb->write_string(datapack_);
}
void Invocation::deserialize(StreamBuffer *sb) {
2024-09-02 21:48:24 -04:00
kind_ = InvocationKind(sb->read_uint8());
actor_ = sb->read_int64();
place_ = sb->read_int64();
datapack_ = sb->read_string();
}
eng::string Invocation::debug_string() const {
eng::ostringstream oss;
2021-11-11 16:23:11 -05:00
oss << "inv[";
switch (kind_) {
2024-09-02 21:48:24 -04:00
case InvocationKind::INVALID: oss << "invalid"; break;
case InvocationKind::LUA_CALL: oss << "lua_call"; break;
case InvocationKind::LUA_EXPR: oss << "lua"; break;
case InvocationKind::FLUSH_PRINTS: oss << "flush_prints"; break;
case InvocationKind::TICK: oss << "tick"; break;
case InvocationKind::LUA_SOURCE: oss << "lua_source"; break;
2021-11-11 16:23:11 -05:00
default: oss << "UNKNOWN"; break;
}
oss << " a=" << actor_;
oss << " p=" << place_;
oss << " dp=" << datapack_.size() << " bytes";
2021-11-11 16:23:11 -05:00
oss << "]";
return oss.str();
}