Skip to content

Commit

Permalink
BUFR: Fix membuffer copy (#193)
Browse files Browse the repository at this point in the history
* BUFR: Fix membuffer copy

* BUFR: Skip WIGOS generation, if it already exists
  • Loading branch information
istvans-mn authored Oct 2, 2024
1 parent ea44877 commit 791c82a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 3 additions & 1 deletion ingest/src/ingest/bufr/ESOHBufr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ std::list<std::string> ESOHBufr::msg() const {
LogEntry("Missing WMO Station number after WMO block",
LogLevel::WARN, __func__, bufr_id));
}
wigos_id.setWmoId(wmo_block * 1000 + wmo_station);
if (!wigos_id.getWigosLocalId().size()) {
wigos_id.setWmoId(wmo_block * 1000 + wmo_station);
}
skip_platform = false;
// platform_check = true;
break;
Expand Down
10 changes: 5 additions & 5 deletions ingest/src/ingest/bufr/NorBufr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,14 +640,14 @@ uint64_t NorBufr::fromBuffer(char *ext_buf, u_int64_t ext_buf_pos,
if (n >= ext_buf_size) {
lb.addLogEntry(
LogEntry("No more BUFR messages", LogLevel::WARN, __func__, bufr_id));
return 0;
return n;
}

// Section0 length
uint64_t slen = 8;
uint8_t sec0[slen];
if (ext_buf_pos + slen < ext_buf_size) {
memcpy(sec0, ext_buf + ext_buf_pos, slen);
if (ext_buf_pos + n + slen < ext_buf_size) {
memcpy(sec0, ext_buf + ext_buf_pos + n, slen);
}

len = NorBufrIO::getBytes(sec0 + 4, 3);
Expand All @@ -660,8 +660,8 @@ uint64_t NorBufr::fromBuffer(char *ext_buf, u_int64_t ext_buf_pos,
buffer = new uint8_t[len];
memcpy(buffer, sec0, slen);

if (ext_buf_pos + len <= ext_buf_size) {
memcpy(buffer + slen, ext_buf + ext_buf_pos + slen, len - slen);
if (ext_buf_pos + n + len <= ext_buf_size) {
memcpy(buffer + slen, ext_buf + ext_buf_pos + n + slen, len - slen);
}

int offset = checkBuffer();
Expand Down
8 changes: 5 additions & 3 deletions ingest/src/ingest/bufr/NorBufrIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ uint64_t NorBufrIO::findBytes(char *buf, unsigned int buf_size, const char *seq,
unsigned int size) {
uint64_t j = 0;
char c;
while (j < size && j < buf_size) {
c = buf[j];
uint64_t position = 0;
while (j < size && position < buf_size) {
c = buf[position];
if (c == seq[j]) {
++j;
} else {
Expand All @@ -74,8 +75,9 @@ uint64_t NorBufrIO::findBytes(char *buf, unsigned int buf_size, const char *seq,
j = 0;
}
}
++position;
}
return (j < size ? ULONG_MAX : j);
return (j < size ? ULONG_MAX : position - size);
}

uint64_t NorBufrIO::getBytes(uint8_t *buffer, int size) {
Expand Down
8 changes: 5 additions & 3 deletions ingest/src/ingest/bufr/bufresohmsg_py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ std::list<std::string> norbufr_bufresohmsg(std::string fname) {
std::list<std::string> norbufr_bufresohmsgmem(char *api_buf, int api_size) {

std::list<std::string> ret;
int position = 0;
uint64_t position = 0;

while (position < api_size) {
while (position < static_cast<uint64_t>(api_size)) {

ESOHBufr *bufr = new ESOHBufr;
// TODO:
Expand All @@ -146,7 +146,9 @@ std::list<std::string> norbufr_bufresohmsgmem(char *api_buf, int api_size) {
bufr->setMsgTemplate(bufr_input_schema);
bufr->setShadowWigos(default_shadow_wigos_py);

int n = bufr->fromBuffer(api_buf, position, api_size);
uint64_t n = bufr->fromBuffer(api_buf, position, api_size);
if (n == ULONG_MAX)
position = ULONG_MAX;
if (n > position) {
position = n;
bufr->setTableB(
Expand Down

1 comment on commit 791c82a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API Unit Test Coverage Report
FileStmtsMissCoverMissing
\_\_init\_\_.py00100% 
datastore_pb2.py655220%34–85
datastore_pb2_grpc.py542750%15–16, 19, 65–80, 121–123, 128–130, 135–137, 142–144, 148–173, 219, 246, 273, 300
export_metrics.py100100% 
grpc_getter.py201145%15–19, 23–26, 30–32, 36–38
locustfile.py15150%1–31
main.py43784%45, 50, 60, 70–71, 81–82
metadata_endpoints.py653152%45–54, 58, 85, 100–219, 223
response_classes.py50100% 
utilities.py1744674%20, 38, 45, 67–70, 78–89, 94–101, 121, 125, 127, 155, 161, 179, 193–194, 198, 214–218, 222–228, 232–234, 264, 268, 290, 295
custom_geo_json
   edr_feature_collection.py60100% 
formatters
   \_\_init\_\_.py110100% 
   covjson.py59198%91
   geojson.py21290%27, 52
openapi
   custom_dimension_examples.py40100% 
   edr_query_parameter_descriptions.py110100% 
   openapi_examples.py130100% 
routers
   \_\_init\_\_.py00100% 
   edr.py101496%348–349, 438–439
   feature.py471960%99–132, 148–153, 159–181
TOTAL72421570% 

API Unit Test Coverage Summary

Tests Skipped Failures Errors Time
30 0 💤 0 ❌ 0 🔥 1.979s ⏱️

Please sign in to comment.