Skip to content

Commit

Permalink
GRIB message validity checker: 7777 and namespace checks
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Jan 10, 2025
1 parent 979354e commit 26475e6
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/accessor/grib_accessor_class_message_is_valid.cc
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ static int check_geoiterator(grib_handle* h)
return err;
}

static int check_7777(grib_handle* h)
{
if (!grib_is_defined(h, "7777")) {
return GRIB_7777_NOT_FOUND;
}
return GRIB_SUCCESS;
}

static int check_steps(grib_handle* h)
{
char stepType[32] = {0,};
Expand Down Expand Up @@ -144,6 +152,30 @@ static int check_section_numbers(grib_handle* h, long edition, const int* sec_nu
return GRIB_SUCCESS;
}

static int check_namespace_keys(grib_handle* h)
{
const char* ns = "ls";
grib_keys_iterator* kiter = grib_keys_iterator_new(h, /*flags=*/0, ns);
if (!kiter) return GRIB_DECODING_ERROR;
int count = 0;
while (grib_keys_iterator_next(kiter)) {
++count;
const char* name = grib_keys_iterator_get_name(kiter);
int type = 0;
grib_get_native_type(h, name, &type);
if ( STR_EQUAL(grib_get_type_name(type), "unknown") ) {
grib_context_log(h->context, GRIB_LOG_ERROR, "Key %s has unknown type", name);
return GRIB_DECODING_ERROR;
}
}
if (count == 0) {
grib_context_log(h->context, GRIB_LOG_ERROR, "Message has no keys in the '%s' namespace", ns);
return GRIB_DECODING_ERROR;
}
grib_keys_iterator_delete(kiter);
return GRIB_SUCCESS;
}

static int check_sections(grib_handle* h)
{
long edition = 0;
Expand Down Expand Up @@ -171,7 +203,9 @@ static proj_func check_functions[] = {
check_field_values,
check_grid_pl_array,
check_geoiterator,
check_steps
check_steps,
check_7777,
check_namespace_keys
};

int grib_accessor_message_is_valid_t::unpack_long(long* val, size_t* len)
Expand Down

0 comments on commit 26475e6

Please sign in to comment.