Less serialization and deserialization of Lua Source, also, Invocation is now simpler

This commit is contained in:
2023-10-19 19:42:33 -04:00
parent 049b0b893a
commit 7104a523b5
16 changed files with 134 additions and 150 deletions

View File

@@ -1,3 +1,39 @@
//////////////////////////////////////////////////////////////////////////
//
// DATAPACK
//
// Invocations contain a field 'datapack' which contains additional
// data for the invocation, packed up in a serialized format. Executing
// the invocation involves unpacking the datapack.
//
// The actual contents of the datapack depends on the type of invocation:
//
// KIND_INVALID:
//
// Nothing.
//
// KIND_PLAN:
//
// Name of a callback function, in plaintext.
//
// KIND_LUA:
//
// A block of lua source code, in plaintext.
//
// KIND_FLUSH_PRINTS:
//
// Line number in ascii.
//
// KIND_TICK:
//
// Nothing.
//
// KIND_LUA_SOURCE:
//
// Packaged lua sourcecode. See drvutil::package_lua_source.
//
//////////////////////////////////////////////////////////////////////////
#ifndef INVOCATION_HPP
#define INVOCATION_HPP
@@ -8,14 +44,6 @@
#include "streambuffer.hpp"
class InvocationData : public eng::map<eng::string, eng::string> {
public:
const eng::string &get(const eng::string &key) const;
void serialize(StreamBuffer *sb) const;
void deserialize(StreamBuffer *sb);
};
class Invocation : public eng::nevernew {
public:
enum Kind {
@@ -31,19 +59,16 @@ private:
Kind kind_;
int64_t actor_;
int64_t place_;
eng::string action_;
InvocationData data_;
eng::string datapack_;
public:
Invocation();
Invocation(Kind kind, int64_t actor, int64_t place, const eng::string &action, const InvocationData &data);
Invocation(Kind kind, int64_t actor, int64_t place, const eng::string &action);
Invocation(Kind kind, int64_t actor, int64_t place, std::string_view datapack);
bool valid() const { return kind_ != KIND_INVALID; }
Kind kind() const { return kind_; }
int64_t actor() const { return actor_; }
int64_t place() const { return place_; }
const eng::string &action() const { return action_; }
const InvocationData &data() const { return data_; }
const eng::string &datapack() const { return datapack_; }
void serialize(StreamBuffer *sb) const;
void deserialize(StreamBuffer *sb);