Switch OpaqueVal::UnserializeType() to return IntrusivePtr

This commit is contained in:
Jon Siwek 2020-05-18 15:25:46 -07:00
parent 83f1a911d7
commit 43f513ca44
3 changed files with 13 additions and 11 deletions

View file

@ -112,7 +112,7 @@ broker::expected<broker::data> OpaqueVal::SerializeType(BroType* t)
return {broker::vector{false, static_cast<uint64_t>(t->Tag())}}; return {broker::vector{false, static_cast<uint64_t>(t->Tag())}};
} }
BroType* OpaqueVal::UnserializeType(const broker::data& data) IntrusivePtr<BroType> OpaqueVal::UnserializeType(const broker::data& data)
{ {
auto v = caf::get_if<broker::vector>(&data); auto v = caf::get_if<broker::vector>(&data);
if ( ! (v && v->size() == 2) ) if ( ! (v && v->size() == 2) )
@ -135,14 +135,14 @@ BroType* OpaqueVal::UnserializeType(const broker::data& data)
if ( ! id->IsType() ) if ( ! id->IsType() )
return nullptr; return nullptr;
return id->GetType()->Ref(); return id->GetType();
} }
auto tag = caf::get_if<uint64_t>(&(*v)[1]); auto tag = caf::get_if<uint64_t>(&(*v)[1]);
if ( ! tag ) if ( ! tag )
return nullptr; return nullptr;
return base_type(static_cast<TypeTag>(*tag))->Ref(); return base_type(static_cast<TypeTag>(*tag));
} }
IntrusivePtr<Val> OpaqueVal::DoClone(CloneState* state) IntrusivePtr<Val> OpaqueVal::DoClone(CloneState* state)
@ -854,8 +854,9 @@ bool BloomFilterVal::DoUnserialize(const broker::data& data)
auto no_type = caf::get_if<broker::none>(&(*v)[0]); auto no_type = caf::get_if<broker::none>(&(*v)[0]);
if ( ! no_type ) if ( ! no_type )
{ {
BroType* t = UnserializeType((*v)[0]); auto t = UnserializeType((*v)[0]);
if ( ! (t && Typify(t)) )
if ( ! (t && Typify(t.get())) )
return false; return false;
} }
@ -957,8 +958,9 @@ bool CardinalityVal::DoUnserialize(const broker::data& data)
auto no_type = caf::get_if<broker::none>(&(*v)[0]); auto no_type = caf::get_if<broker::none>(&(*v)[0]);
if ( ! no_type ) if ( ! no_type )
{ {
BroType* t = UnserializeType((*v)[0]); auto t = UnserializeType((*v)[0]);
if ( ! (t && Typify(t)) )
if ( ! (t && Typify(t.get())) )
return false; return false;
} }

View file

@ -154,7 +154,7 @@ protected:
* Helper function for derived class that need to restore a type * Helper function for derived class that need to restore a type
* during unserialization. Returns the type at reference count +1. * during unserialization. Returns the type at reference count +1.
*/ */
static BroType* UnserializeType(const broker::data& data); static IntrusivePtr<BroType> UnserializeType(const broker::data& data);
}; };
namespace probabilistic { namespace probabilistic {

View file

@ -479,12 +479,12 @@ bool TopkVal::DoUnserialize(const broker::data& data)
auto no_type = caf::get_if<broker::none>(&(*v)[3]); auto no_type = caf::get_if<broker::none>(&(*v)[3]);
if ( ! no_type ) if ( ! no_type )
{ {
BroType* t = UnserializeType((*v)[3]); auto t = UnserializeType((*v)[3]);
if ( ! t ) if ( ! t )
return false; return false;
Typify(t); Typify(t.get());
Unref(t);
} }
uint64_t i = 0; uint64_t i = 0;