diff --git a/definitions/boot.def b/definitions/boot.def index dc6f71b94..5cbac2743 100644 --- a/definitions/boot.def +++ b/definitions/boot.def @@ -11,8 +11,6 @@ constant definitionFilesVersion="2.0.0.0" : hidden; constant internalVersion=30 : hidden; meta checkInternalVersion check_internal_version(internalVersion) : hidden; -meta isMessageValid message_is_valid() : hidden; - # ECC-806: Local concepts precedence order preferLocalConceptsEnvVar = getenv("ECCODES_GRIB_PREFER_LOCAL_CONCEPTS","0") : hidden; transient preferLocalConcepts = preferLocalConceptsEnvVar : hidden; @@ -126,3 +124,5 @@ if(kindOfProduct == `WRAP`){ constant WRAPstr="WRAP"; alias ls.identifier=WRAPstr; } + +meta isMessageValid message_is_valid(kindOfProduct) : hidden; diff --git a/src/accessor/grib_accessor_class_message_is_valid.cc b/src/accessor/grib_accessor_class_message_is_valid.cc index 522a0e360..a467c88f0 100644 --- a/src/accessor/grib_accessor_class_message_is_valid.cc +++ b/src/accessor/grib_accessor_class_message_is_valid.cc @@ -13,9 +13,13 @@ grib_accessor_message_is_valid_t _grib_accessor_message_is_valid{}; grib_accessor* grib_accessor_message_is_valid = &_grib_accessor_message_is_valid; -void grib_accessor_message_is_valid_t::init(const long l, grib_arguments* c) +void grib_accessor_message_is_valid_t::init(const long l, grib_arguments* arg) { - grib_accessor_long_t::init(l, c); + grib_accessor_long_t::init(l, arg); + + grib_handle* h = grib_handle_of_accessor(this); + product_ = arg->get_name(h, 0); + flags_ |= GRIB_ACCESSOR_FLAG_READ_ONLY; length_ = 0; } @@ -96,10 +100,16 @@ int grib_accessor_message_is_valid_t::unpack_long(long* val, size_t* len) { int ret = 0; grib_handle* h = grib_handle_of_accessor(this); + *len = 1; *val = 1; // Assume message is valid - if (h->product_kind != PRODUCT_GRIB) { + char product[32] = {0,}; + size_t size = sizeof(product) / sizeof(*product); + ret = grib_get_string(h, product_, product, &size); + if (ret) return ret; + + if (!STR_EQUAL(product, "GRIB")) { grib_context_log(h->context, GRIB_LOG_ERROR, "Validity checks only implemented for GRIB messages"); *val = 0; return GRIB_NOT_IMPLEMENTED; diff --git a/src/accessor/grib_accessor_class_message_is_valid.h b/src/accessor/grib_accessor_class_message_is_valid.h index 9ebd54a27..5d380362c 100644 --- a/src/accessor/grib_accessor_class_message_is_valid.h +++ b/src/accessor/grib_accessor_class_message_is_valid.h @@ -20,4 +20,7 @@ class grib_accessor_message_is_valid_t : public grib_accessor_long_t grib_accessor* create_empty_accessor() override { return new grib_accessor_message_is_valid_t{}; } int unpack_long(long* val, size_t* len) override; void init(const long, grib_arguments*) override; + +private: + const char* product_ = nullptr; }; diff --git a/tests/grib_check_message_validity.sh b/tests/grib_check_message_validity.sh index d14b92533..f05f34139 100755 --- a/tests/grib_check_message_validity.sh +++ b/tests/grib_check_message_validity.sh @@ -24,8 +24,8 @@ cat >$tempFilt<$tempText +grep -q "Invalid Ni" $tempText grib_check_key_equals $tempGrib isMessageValid 0 grib_check_key_equals $sample isMessageValid 1 @@ -37,15 +37,16 @@ cat >$tempFilt<$tempText +grep -q "Invalid PL array" $tempText grib_check_key_equals $tempGrib isMessageValid 0 # Check data values # ------------------------------ ${tools_dir}/grib_set -s bitsPerValue=25 $data_dir/sample.grib2 $tempGrib -grib_check_key_equals $tempGrib isMessageValid 0 +grib_check_key_equals $tempGrib isMessageValid 0 2>$tempText +grep -q "Data section size mismatch" $tempText # Clean up