Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions specification/src/main/asciidoc/chapters/Sparkplug_6_Payloads.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,19 @@ than for a metric. A metric's properties are carried in its properties field.*#
** [tck-testable tck-id-payloads-metric-datatype-req]#[yellow-background]*[tck-id-payloads-metric-datatype-req] The
datatype MUST be included with each metric definition in NBIRTH and DBIRTH messages.*#
** [tck-testable tck-id-payloads-metric-datatype-not-req]#[yellow-background]*[tck-id-payloads-metric-datatype-not-req] The
datatype SHOULD NOT be included with metric definitions in NDATA, NCMD, DDATA, and DCMD messages.*#
Metric's own datatype field MUST NOT be included with a metric in NDATA or DDATA messages in the
Google Protocol Buffers encoding. A metric's datatype is established by the message that defines
it, and a change of datatype is published by amending that definition rather than alongside a
value.*#
*** Non-normative comment: a Metric's own datatype field and the datatype of the TypedValue that
carries the value are separate fields in that encoding, and only the Metric's is omitted. The
TypedValue's selects the field the value occupies and is therefore structural rather than metadata.
The JSON encoding flattens a Metric's TypedValue into the enclosing Metric, as the
link:#payloads_json_typed_values[Typed Values] section requires, so a metric carrying a value has a
single 'datatype' key which is the TypedValue's. There is no separate Metric datatype field there
for this rule to govern, which is why it names the Protocol Buffers encoding.
*** Non-normative comment: NCMD and DCMD are not covered, because a Command invocation is
identified by a metric datatype of Command.
* *quality*
** This defines the quality of the value associated with the metric. It is defined in the
link:#payloads_p_quality[Quality] section. This property is optional and is only required if the
Expand Down Expand Up @@ -3754,7 +3766,11 @@ Google Protocol Buffers encoding, the two MUST be equal, and the same applies to
[tck-testable tck-id-payloads-json-typedvalue-carries-both]#[yellow-background]*[tck-id-payloads-json-typedvalue-carries-both] The
single 'datatype' and 'is_null' key a flattened JSON value carries represents both, so an
application converting a JSON payload to the Google Protocol Buffers encoding MUST set the Metric
field and the TypedValue field from it.*#
field and the TypedValue field from it, except that where the Protocol Buffers encoding does not
permit the Metric datatype field it sets the TypedValue field only.*#
Non-normative comment: without that exception, converting a conforming JSON payload would produce a
Protocol Buffers payload that breaks the rule the JSON payload was keeping, because the one JSON
key stands for two fields of which only one is permitted.

[tck-testable tck-id-payloads-json-parameter-is-null]#[yellow-background]*[tck-id-payloads-json-parameter-is-null] A
Template.Parameter whose value is null MUST carry 'is_null' set to true and omit 'value', as any
Expand Down Expand Up @@ -4045,7 +4061,9 @@ Sparkplug JSON payload MUST validate against the JSON Schema below.*#
The following is a non-normative example of one DDATA message shown in both encodings, so the two
may be compared directly. The payload reports a single aliased Float metric.

The spPv4.0 form, shown as a structural illustration of the Protocol Buffers message:
The spPv4.0 form, shown as a structural illustration of the Protocol Buffers message. The datatype
shown is the TypedValue's, which the message carries; the Metric's own datatype field is absent, as
a DATA message requires:

----
Acme/Dublin/Packaging/spPv4.0/DDATA/EdgeNode1/Line3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ private void checkCommandTopicPayload(final @NotNull String clientId, final @Not
final PayloadOrBuilder sparkplugPayload = Utils.getSparkplugPayload(packet);
if (sparkplugPayload != null) {
checkAliasInData(sparkplugPayload, topic);
checkMetricsDataTypeNotRec(sparkplugPayload, topic);
checkPayloadsNameRequirement(sparkplugPayload);
} else {
logger.error("Skip Edge payload validation - no sparkplug payload.");
Expand Down Expand Up @@ -486,19 +485,20 @@ public void checkAliasInData(final @NotNull PayloadOrBuilder sparkplugPayload, S
id = ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ)
public void checkMetricsDataTypeNotRec(final @NotNull PayloadOrBuilder sparkplugPayload, String topic) {
logger.debug(
"Check Req: The datatype SHOULD NOT be included with metric definitions in NDATA, NCMD, DDATA, and DCMD messages.");
"Check Req: The datatype MUST NOT be included with a metric in NDATA or DDATA messages.");
boolean isValid = true;
if (topic.contains(TOPIC_PATH_NDATA) || topic.contains(TOPIC_PATH_DDATA) || topic.contains(TOPIC_PATH_NCMD)
|| topic.contains(TOPIC_PATH_DCMD)) {
// The Metric's own datatype field, which is separate from the TypedValue's. NCMD and DCMD
// are not covered: a Command invocation is identified by a metric datatype of Command.
if (topic.contains(TOPIC_PATH_NDATA) || topic.contains(TOPIC_PATH_DDATA)) {
for (Metric m : sparkplugPayload.getContent().getMetricsList()) {
if (m.hasDatatype()) {
logger.info("On topic={} - Invalid payload: {}", topic, sparkplugPayload);
isValid = false;
break;
}
}
testResults.put(ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ,
Utils.setShouldResult(isValid, PAYLOADS_METRIC_DATATYPE_NOT_REQ));
Utils.setResultIfNotFail(testResults, isValid, ID_PAYLOADS_METRIC_DATATYPE_NOT_REQ,
PAYLOADS_METRIC_DATATYPE_NOT_REQ);
}
}

Expand Down
Loading