How to decoding the data to be subscribed
Hello kevin, I want to subcribe a node which is encoded.Such as the CustomDataTypeNode in the example.And the codec is
public static class Codec extends GenericDataTypeCodec<CustomStructType> {
@Override
public Class<CustomStructType> getType() {
return CustomStructType.class;
}
@Override
public CustomStructType decode(
SerializationContext context,
UaDecoder decoder) throws UaSerializationException {
String foo = decoder.readString("Foo");
UInteger bar = decoder.readUInt32("Bar");
boolean baz = decoder.readBoolean("Baz");
return new CustomStructType(foo, bar, baz);
}
@Override
public void encode(
SerializationContext context,
UaEncoder encoder, CustomStructType value) throws UaSerializationException {
encoder.writeString("Foo", value.foo);
encoder.writeUInt32("Bar", value.bar);
encoder.writeBoolean("Baz", value.baz);
}
}
And the decoding step I have already know
Variant variant = value.getValue();
ExtensionObject xo = (ExtensionObject) variant.getValue();
CustomStructType decoded = (CustomStructType) xo.decode(
client.getSerializationContext()
);
However, if I want to subscribe another node, I have to repeat in this way to match the data decoding.Is there any easier way to implement this?Or is the there any generic decoding utils in milo?
If the server you're connecting to has defined all the custom types in its DataTypeDictionary and they are properly exposed in the address space then yes, the client will automatically read those and you can access them generically.
By default the client is configured with a GenericBsdParser instance that reads custom types as a org.eclipse.milo.opcua.binaryschema.Struct instance. There's also a JsonBsdParser you can configure that will read them as a GSON JsonObject.
This won't work against the Milo example server (at least not in 0.3.x... should work in dev/0.4 branch), but it generally works with demo servers from other vendors.
If the server you're connecting to has defined all the custom types in its DataTypeDictionary and they are properly exposed in the address space then yes, the client will automatically read those and you can access them generically.
By default the client is configured with a
GenericBsdParserinstance that reads custom types as aorg.eclipse.milo.opcua.binaryschema.Structinstance. There's also aJsonBsdParseryou can configure that will read them as a GSONJsonObject.This won't work against the Milo example server (at least not in 0.3.x... should work in
dev/0.4branch), but it generally works with demo servers from other vendors.
3Q,I will work on it then
Take a look at UnifiedAutomationReadCustomDataTypeExample.
Take a look at
UnifiedAutomationReadCustomDataTypeExample.
OK,and I want to know if it works well on the open62541 server,too?
It should work with open62541 or any other server as long as they put the information about the datatype into the address space.