123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- package at.acdp.opcur.opc;
- /*
- * Copyright (c) 2017 Kevin Herron
- *
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * and Eclipse Distribution License v1.0 which accompany this distribution.
- *
- * The Eclipse Public License is available at
- * http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.html.
- */
- import com.google.common.base.MoreObjects;
- import com.google.common.base.Objects;
- import org.eclipse.milo.opcua.stack.core.UaSerializationException;
- import org.eclipse.milo.opcua.stack.core.serialization.UaDecoder;
- import org.eclipse.milo.opcua.stack.core.serialization.UaEncoder;
- import org.eclipse.milo.opcua.stack.core.serialization.codecs.GenericDataTypeCodec;
- import org.eclipse.milo.opcua.stack.core.serialization.codecs.SerializationContext;
- import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger;
- import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
- public class CustomDataType {
- private final String foo;
- private final UInteger bar;
- private final boolean baz;
- public CustomDataType() {
- this(null, uint(0), false);
- }
- public CustomDataType(String foo, UInteger bar, boolean baz) {
- this.foo = foo;
- this.bar = bar;
- this.baz = baz;
- }
- public String getFoo() {
- return foo;
- }
- public UInteger getBar() {
- return bar;
- }
- public boolean isBaz() {
- return baz;
- }
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
- CustomDataType that = (CustomDataType) o;
- return baz == that.baz &&
- Objects.equal(foo, that.foo) &&
- Objects.equal(bar, that.bar);
- }
- @Override
- public int hashCode() {
- return Objects.hashCode(foo, bar, baz);
- }
- @Override
- public String toString() {
- return MoreObjects.toStringHelper(this)
- .add("foo", foo)
- .add("bar", bar)
- .add("baz", baz)
- .toString();
- }
- public static class Codec extends GenericDataTypeCodec<CustomDataType> {
- @Override
- public Class<CustomDataType> getType() {
- return CustomDataType.class;
- }
- @Override
- public CustomDataType decode(
- SerializationContext context,
- UaDecoder decoder) throws UaSerializationException {
- String foo = decoder.readString("Foo");
- UInteger bar = decoder.readUInt32("Bar");
- boolean baz = decoder.readBoolean("Baz");
- return new CustomDataType(foo, bar, baz);
- }
- @Override
- public void encode(
- SerializationContext context,
- CustomDataType customDataType,
- UaEncoder encoder) throws UaSerializationException {
- encoder.writeString("Foo", customDataType.foo);
- encoder.writeUInt32("Bar", customDataType.bar);
- encoder.writeBoolean("Baz", customDataType.baz);
- }
- }
- }
|