diff --git a/NEWS b/NEWS index a9b426b9a9..e458562c8c 100644 --- a/NEWS +++ b/NEWS @@ -199,6 +199,9 @@ Deprecated Functionality - ``RecordVal::Lookup(int)`` is deprecated, use ``RecordVal::GetField(int)``. +- ``RecordVal::LookupWithDefault(int)`` is deprecated, use + ``RecordVal::GetFieldOrDefault(int)``. + Zeek 3.1.0 ========== diff --git a/src/Val.cc b/src/Val.cc index f31c56213d..f4c0f72d8b 100644 --- a/src/Val.cc +++ b/src/Val.cc @@ -580,7 +580,7 @@ static void BuildJSON(threading::formatter::JSON::NullDoubleWriter& writer, Val* for ( auto i = 0; i < rt->NumFields(); ++i ) { - auto value = rval->LookupWithDefault(i); + auto value = rval->GetFieldOrDefault(i); if ( value && ( ! only_loggable || rt->FieldHasAttr(i, ATTR_LOG) ) ) { @@ -2741,7 +2741,7 @@ void RecordVal::Assign(int field, Val* new_val) Assign(field, {AdoptRef{}, new_val}); } -IntrusivePtr RecordVal::LookupWithDefault(int field) const +IntrusivePtr RecordVal::GetFieldOrDefault(int field) const { const auto& val = (*AsRecord())[field]; @@ -2788,7 +2788,7 @@ IntrusivePtr RecordVal::Lookup(const char* field, bool with_default) const if ( idx < 0 ) reporter->InternalError("missing record field: %s", field); - return with_default ? LookupWithDefault(idx) : GetField(idx); + return with_default ? GetFieldOrDefault(idx) : GetField(idx); } IntrusivePtr RecordVal::CoerceTo(IntrusivePtr t, diff --git a/src/Val.h b/src/Val.h index 8671298135..7401f9b8f3 100644 --- a/src/Val.h +++ b/src/Val.h @@ -986,7 +986,19 @@ public: IntrusivePtr GetField(int field) const { return cast_intrusive(GetField(field)); } - IntrusivePtr LookupWithDefault(int field) const; + /** + * Returns the value of a given field index if it's previously been + * assigned, * or else returns the value created from evaluating the + * record field's &default expression. + * @param field The field index to retrieve. + * @return The value at the given field index or the default value if + * the field hasn't been assigned yet. + */ + IntrusivePtr GetFieldOrDefault(int field) const; + + [[deprecated("Remove in v4.1. Use GetFieldOrDefault().")]] + Val* LookupWithDefault(int field) const + { return GetFieldOrDefault(field).release(); } /** * Looks up the value of a field by field name. If the field doesn't diff --git a/src/broker/Data.cc b/src/broker/Data.cc index 82f41be02d..35dc12733a 100644 --- a/src/broker/Data.cc +++ b/src/broker/Data.cc @@ -971,7 +971,7 @@ broker::expected bro_broker::val_to_data(const Val* v) for ( auto i = 0u; i < num_fields; ++i ) { - auto item_val = rec->LookupWithDefault(i); + auto item_val = rec->GetFieldOrDefault(i); if ( ! item_val ) { diff --git a/src/file_analysis/File.cc b/src/file_analysis/File.cc index e514c9a266..c691880300 100644 --- a/src/file_analysis/File.cc +++ b/src/file_analysis/File.cc @@ -161,13 +161,13 @@ void File::RaiseFileOverNewConnection(Connection* conn, bool is_orig) uint64_t File::LookupFieldDefaultCount(int idx) const { - auto v = val->LookupWithDefault(idx); + auto v = val->GetFieldOrDefault(idx); return v->AsCount(); } double File::LookupFieldDefaultInterval(int idx) const { - auto v = val->LookupWithDefault(idx); + auto v = val->GetFieldOrDefault(idx); return v->AsInterval(); } diff --git a/src/file_analysis/File.h b/src/file_analysis/File.h index 82f286f70e..f4278500a5 100644 --- a/src/file_analysis/File.h +++ b/src/file_analysis/File.h @@ -259,7 +259,7 @@ protected: void IncrementByteCount(uint64_t size, int field_idx); /** - * Wrapper to RecordVal::LookupWithDefault for the field in #val at index + * Wrapper to RecordVal::GetFieldOrDefault for the field in #val at index * \a idx which automatically unrefs the Val and returns a converted value. * @param idx the index of a field of type "count" in \c fa_file. * @return the value of the field, which may be it &default. @@ -267,7 +267,7 @@ protected: uint64_t LookupFieldDefaultCount(int idx) const; /** - * Wrapper to RecordVal::LookupWithDefault for the field in #val at index + * Wrapper to RecordVal::GetFieldOrDefault for the field in #val at index * \a idx which automatically unrefs the Val and returns a converted value. * @param idx the index of a field of type "interval" in \c fa_file. * @return the value of the field, which may be it &default. diff --git a/src/input/Manager.cc b/src/input/Manager.cc index af80e6cbdb..d72d56a8b9 100644 --- a/src/input/Manager.cc +++ b/src/input/Manager.cc @@ -1005,13 +1005,13 @@ Val* Manager::RecordValToIndexVal(RecordVal *r) const int num_fields = type->NumFields(); if ( num_fields == 1 && type->FieldDecl(0)->type->Tag() != TYPE_RECORD ) - idxval = r->LookupWithDefault(0); + idxval = r->GetFieldOrDefault(0); else { auto l = make_intrusive(TYPE_ANY); for ( int j = 0 ; j < num_fields; j++ ) - l->Append(r->LookupWithDefault(j)); + l->Append(r->GetFieldOrDefault(j)); idxval = std::move(l); }