2021-07-19 15:32:34 -04:00
|
|
|
|
2022-02-23 23:08:28 -05:00
|
|
|
#include "wrap-string.hpp"
|
|
|
|
|
#include "wrap-map.hpp"
|
|
|
|
|
#include "wrap-deque.hpp"
|
|
|
|
|
#include "wrap-sstream.hpp"
|
|
|
|
|
|
2021-07-19 15:32:34 -04:00
|
|
|
#include "invocation.hpp"
|
|
|
|
|
|
2021-10-15 14:47:12 -04:00
|
|
|
const std::string &InvocationData::get(const std::string &key) const {
|
|
|
|
|
static std::string blank_;
|
|
|
|
|
auto iter = find(key);
|
|
|
|
|
if (iter == end()) {
|
|
|
|
|
return blank_;
|
|
|
|
|
} else {
|
|
|
|
|
return iter->second;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-07-19 15:32:34 -04:00
|
|
|
|
|
|
|
|
void InvocationData::serialize(StreamBuffer *sb) const {
|
|
|
|
|
assert(int(size()) < 65536);
|
|
|
|
|
sb->write_uint16(size());
|
|
|
|
|
for (const auto &pair : *this) {
|
|
|
|
|
sb->write_string(pair.first);
|
|
|
|
|
sb->write_string(pair.second);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InvocationData::deserialize(StreamBuffer *sb) {
|
|
|
|
|
clear();
|
|
|
|
|
int size = sb->read_uint16();
|
|
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
|
std::string key = sb->read_string();
|
|
|
|
|
std::string val = sb->read_string();
|
|
|
|
|
(*this)[key] = val;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Invocation::Invocation() : kind_(KIND_INVALID), actor_(0), place_(0) {}
|
|
|
|
|
|
|
|
|
|
Invocation::Invocation(Kind kind, int64_t actor, int64_t place, const std::string &action, const InvocationData &data)
|
|
|
|
|
: kind_(kind), actor_(actor), place_(place), action_(action), data_(data) {}
|
|
|
|
|
|
2021-11-16 12:20:11 -05:00
|
|
|
Invocation::Invocation(Kind kind, int64_t actor, int64_t place, const std::string &action)
|
|
|
|
|
: kind_(kind), actor_(actor), place_(place), action_(action) {}
|
|
|
|
|
|
2021-07-19 15:32:34 -04:00
|
|
|
void Invocation::serialize(StreamBuffer *sb) const {
|
|
|
|
|
sb->write_uint8(kind_);
|
|
|
|
|
sb->write_int64(actor_);
|
|
|
|
|
sb->write_int64(place_);
|
|
|
|
|
sb->write_string(action_);
|
|
|
|
|
data_.serialize(sb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Invocation::deserialize(StreamBuffer *sb) {
|
|
|
|
|
kind_ = Kind(sb->read_uint8());
|
|
|
|
|
actor_ = sb->read_int64();
|
|
|
|
|
place_ = sb->read_int64();
|
|
|
|
|
action_ = sb->read_string();
|
|
|
|
|
data_.deserialize(sb);
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-11 16:23:11 -05:00
|
|
|
std::string Invocation::debug_string() {
|
|
|
|
|
std::ostringstream oss;
|
|
|
|
|
oss << "inv[";
|
|
|
|
|
switch (kind_) {
|
|
|
|
|
case KIND_INVALID: oss << "invalid"; break;
|
|
|
|
|
case KIND_PLAN: oss << "plan"; break;
|
|
|
|
|
case KIND_LUA: oss << "lua"; break;
|
|
|
|
|
case KIND_FLUSH_PRINTS: oss << "flush_prints"; break;
|
2021-11-26 15:45:36 -05:00
|
|
|
case KIND_TICK: oss << "tick"; break;
|
2021-12-15 14:18:19 -05:00
|
|
|
case KIND_LUA_SOURCE: oss << "lua_source"; break;
|
2021-11-11 16:23:11 -05:00
|
|
|
default: oss << "UNKNOWN"; break;
|
|
|
|
|
}
|
|
|
|
|
oss << " a=" << actor_;
|
|
|
|
|
oss << " p=" << place_;
|
2021-12-15 14:18:19 -05:00
|
|
|
if (kind_ != KIND_LUA_SOURCE) {
|
|
|
|
|
oss << " " << action_;
|
|
|
|
|
}
|
2021-11-11 16:23:11 -05:00
|
|
|
for (const auto &pair : data_) {
|
|
|
|
|
oss << " " << pair.first << "=" << pair.second;
|
|
|
|
|
}
|
|
|
|
|
oss << "]";
|
|
|
|
|
return oss.str();
|
|
|
|
|
}
|