fix(drivers): R5 minors - MTConnect session publish+generation atomic and superseded pump joined; MQTT birth-typed writes use the birth's own datatype; AbLegacy dead init join removed + Dispose join test; docs (#602)
Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
@@ -287,6 +287,56 @@ public sealed class MqttWriteEncoderTests
|
||||
MqttMode.SparkplugB, Sparkplug("Filler1", DriverDataType.Reference), "ref", out _)
|
||||
.ShouldBe(MqttWriteEncodeError.UnsupportedDataType);
|
||||
|
||||
// ---- Birth-typed writes keep the birth's OWN Sparkplug datatype (review R5 MINOR-4) ----------
|
||||
|
||||
private static Payload.Types.Metric EncodeBirth(TahuDataType birth, object value)
|
||||
{
|
||||
var error = MqttWriteEncoder.TryEncode(
|
||||
MqttMode.SparkplugB, Sparkplug("Filler1", DriverDataType.Float64) with { DataTypeAuthored = false }, value,
|
||||
out var encoded, birth.ToDriverDataType(), birth);
|
||||
error.ShouldBe(MqttWriteEncodeError.None);
|
||||
return Payload.Parser.ParseFrom(encoded.Payload).Metrics.Single();
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TahuDataType.Int8, (sbyte)-5)]
|
||||
[InlineData(TahuDataType.Uint8, (byte)200)]
|
||||
[InlineData(TahuDataType.Text, "hello")]
|
||||
[InlineData(TahuDataType.Uuid, "123e4567-e89b-12d3-a456-426614174000")]
|
||||
public void A_birth_typed_write_is_commanded_with_the_births_own_datatype(TahuDataType birth, object value)
|
||||
=> ((TahuDataType)EncodeBirth(birth, value).Datatype).ShouldBe(birth);
|
||||
|
||||
[Fact]
|
||||
public void A_birth_typed_bytes_write_carries_bytes_with_the_bytes_datatype()
|
||||
{
|
||||
var metric = EncodeBirth(TahuDataType.Bytes, new byte[] { 1, 2, 3 });
|
||||
((TahuDataType)metric.Datatype).ShouldBe(TahuDataType.Bytes);
|
||||
metric.BytesValue.ToByteArray().ShouldBe([1, 2, 3]);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(TahuDataType.Int32Array)]
|
||||
[InlineData(TahuDataType.DoubleArray)]
|
||||
[InlineData(TahuDataType.DataSet)]
|
||||
[InlineData(TahuDataType.Template)]
|
||||
public void A_birth_type_with_no_command_encoding_is_refused_never_sent_as_another_type(TahuDataType birth)
|
||||
{
|
||||
MqttWriteEncoder.TryEncode(
|
||||
MqttMode.SparkplugB, Sparkplug("Filler1") with { DataTypeAuthored = false }, 1, out var encoded,
|
||||
birth.ToDriverDataType(), birth)
|
||||
.ShouldBe(MqttWriteEncodeError.UnsupportedDataType);
|
||||
encoded.Payload.ShouldBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void An_authored_type_still_wins_over_the_birth_type()
|
||||
{
|
||||
var def = Sparkplug("Filler1", DriverDataType.Int32) with { DataTypeAuthored = true };
|
||||
MqttWriteEncoder.TryEncode(MqttMode.SparkplugB, def, 7, out var encoded, null, TahuDataType.Text)
|
||||
.ShouldBe(MqttWriteEncodeError.None);
|
||||
((TahuDataType)Payload.Parser.ParseFrom(encoded.Payload).Metrics.Single().Datatype).ShouldBe(TahuDataType.Int32);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void The_mode_decides_the_shape_not_the_blob()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user