simplifications to the Frame class now that it no longer has to support old-style captures

This commit is contained in:
Vern Paxson 2023-06-16 15:39:58 -07:00 committed by Arne Welzel
parent 82588ca311
commit 6ac348d77d
2 changed files with 9 additions and 32 deletions

View file

@ -139,11 +139,8 @@ static bool val_is_func(const ValPtr& v, ScriptFunc* func)
return v->AsFunc() == func;
}
broker::expected<broker::data> Frame::SerializeCopyFrame()
broker::expected<broker::data> Frame::Serialize()
{
broker::vector rval;
rval.emplace_back(std::string("CopyFrame"));
broker::vector body;
for ( int i = 0; i < size; ++i )
@ -158,28 +155,18 @@ broker::expected<broker::data> Frame::SerializeCopyFrame()
body.emplace_back(std::move(val_tuple));
}
broker::vector rval;
rval.emplace_back(std::move(body));
return {std::move(rval)};
}
std::pair<bool, FramePtr> Frame::Unserialize(const broker::vector& data,
const std::optional<FuncType::CaptureList>& captures)
std::pair<bool, FramePtr> Frame::Unserialize(const broker::vector& data)
{
if ( data.size() == 0 )
return std::make_pair(true, nullptr);
auto where = data.begin();
auto has_name = broker::get_if<std::string>(*where);
if ( ! has_name )
return std::make_pair(false, nullptr);
std::advance(where, 1);
if ( captures )
ASSERT(*has_name == "CopyFrame");
auto has_body = broker::get_if<broker::vector>(*where);
if ( ! has_body )
return std::make_pair(false, nullptr);

View file

@ -172,16 +172,11 @@ public:
Frame* CloneForTrigger() const;
/**
* Serializes the frame in support of copy semantics for lambdas:
*
* [ "CopyFrame", serialized_values ]
*
* where serialized_values are two-element vectors. A serialized_value
* has the result of calling broker::data_to_val on the value in the
* first index, and an integer representing that value's type in the
* second index.
* Serializes the frame (only done for lambda/when captures) as a
* sequence of two-element vectors, the first element reflecting
* the frame value, the second its type.
*/
broker::expected<broker::data> SerializeCopyFrame();
broker::expected<broker::data> Serialize();
/**
* Instantiates a Frame from a serialized one.
@ -189,13 +184,8 @@ public:
* @return a pair in which the first item is the status of the serialization;
* and the second is the unserialized frame with reference count +1, or
* null if the serialization wasn't successful.
*
* The *captures* argument, if non-nil, specifies that the frame
* reflects captures with copy-semantics rather than deprecated
* reference semantics.
*/
static std::pair<bool, FramePtr>
Unserialize(const broker::vector& data, const std::optional<FuncType::CaptureList>& captures);
static std::pair<bool, FramePtr> Unserialize(const broker::vector& data);
// If the frame is run in the context of a trigger condition evaluation,
// the trigger needs to be registered.
@ -246,7 +236,7 @@ private:
*/
int current_offset;
/** Frame used for captures (if any) with copy semantics. */
/** Frame used for lambda/when captures. */
Frame* captures;
/** Maps IDs to offsets into the "captures" frame. If the ID