Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem Decoding Incoming Messages due to Usage of long_value for uint32 #397

Open
burakatalay opened this issue Sep 4, 2024 · 0 comments

Comments

@burakatalay
Copy link

Hello,

We are using the JavaScript sparkplug-payload library to build a cloud system where IoT devices are sending data to using Sparkplug specification. Currently we have an issue where we can't decode the uint32 values that are being sent by the devices. The Sparkplug specification states the following:

oneof value {
    uint32 int_value = 10;
    uint64 long_value = 11;
    float float_value = 12;
    double double_value = 13;
    bool boolean_value = 14;
    string string_value = 15;
    bytes bytes_value = 16; // Bytes, File
    DataSet dataset_value = 17;
    Template template_value = 18;
    MetricValueExtension extension_value = 19;
}

Based on this, our embedded developers are sending us values, and for uint32 they are using int_value. An example is as follows:

metrics {
  name: "Metric_Name"
  alias: 1130
  timestamp: 1723882554000
  datatype: 7
  properties {
    keys: "uom"
    keys: "min"
    keys: "max"
    values {
      type: 12
      string_value: "seconds"
    }
    values {
      type: 7
      int_value: 0
    }
    values {
      type: 7
      int_value: 4294967295
    }
  }
  int_value: 1723882554
}

As you can see, they are specifying the data type as 7, which corresponds to uint32 in the Sparkplug specification, and they are setting the int_value.

However, when decoding this using the sparkplug-payload library, we are getting the value as null.

Upon investigating the library code, we found the following part in the decoding:

 case 7: // UInt32
            if (object.longValue instanceof Long) {
                return object.longValue.toInt() as T;
            } else {
                return object.longValue as T;
            }

We also found this issue from 3 years ago, where somebody else asked about this and it seems like a decision was made to change the handling of uint32 values as int_value. However, the current version is still treating uint32 as long_value instead of int_value.

So, from our understanding, the library right now does not conform with the Sparkplug specification. Is this actually the case, or are we missing something here? If so, is this intentional? Are we supposed to send long_value for uint32 metrics?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant