Skip to content

Commit

Permalink
First draft of struct/enum generation for 1.04
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinherron committed Aug 12, 2021
1 parent ae72527 commit a8b80b9
Show file tree
Hide file tree
Showing 348 changed files with 14,473 additions and 2,352 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -31,6 +31,7 @@
import org.eclipse.milo.opcua.stack.core.types.builtin.ExtensionObject;
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText;
import org.eclipse.milo.opcua.stack.core.types.builtin.NodeId;
import org.eclipse.milo.opcua.stack.core.types.builtin.OptionSetUInteger;
import org.eclipse.milo.opcua.stack.core.types.builtin.QualifiedName;
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode;
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant;
Expand Down Expand Up @@ -582,6 +583,7 @@ public void writeVariant(Variant variant) throws UaSerializationException {
} else {
boolean structure = false;
boolean enumeration = false;
boolean optionSet = false;
Class<?> valueClass = getClass(value);

if (UaStructure.class.isAssignableFrom(valueClass)) {
Expand All @@ -590,6 +592,9 @@ public void writeVariant(Variant variant) throws UaSerializationException {
} else if (UaEnumeration.class.isAssignableFrom(valueClass)) {
valueClass = Integer.class;
enumeration = true;
} else if (OptionSetUInteger.class.isAssignableFrom(valueClass)) {
valueClass = ((OptionSetUInteger<?>) value).getValue().getClass();
optionSet = true;
}

int typeId = TypeUtil.getBuiltinTypeId(valueClass);
Expand All @@ -611,7 +616,7 @@ public void writeVariant(Variant variant) throws UaSerializationException {
for (int i = 0; i < length; i++) {
Object o = Array.get(value, i);

writeValue(o, typeId, structure, enumeration);
writeValue(o, typeId, structure, enumeration, optionSet);
}
} else {
buffer.writeByte(typeId | 0xC0);
Expand All @@ -623,7 +628,7 @@ public void writeVariant(Variant variant) throws UaSerializationException {
for (int i = 0; i < length; i++) {
Object o = Array.get(flattened, i);

writeValue(o, typeId, structure, enumeration);
writeValue(o, typeId, structure, enumeration, optionSet);
}

writeInt32(dimensions.length);
Expand All @@ -634,14 +639,14 @@ public void writeVariant(Variant variant) throws UaSerializationException {
} else {
buffer.writeByte(typeId);

writeValue(value, typeId, structure, enumeration);
writeValue(value, typeId, structure, enumeration, optionSet);
}
}
}

// endregion

private void writeValue(Object value, int typeId, boolean structure, boolean enumeration) {
private void writeValue(Object value, int typeId, boolean structure, boolean enumeration, boolean optionSet) {
if (structure) {
UaStructure struct = (UaStructure) value;

Expand All @@ -650,6 +655,8 @@ private void writeValue(Object value, int typeId, boolean structure, boolean enu
writeBuiltinType(typeId, extensionObject);
} else if (enumeration) {
writeBuiltinType(typeId, ((UaEnumeration) value).getValue());
} else if (optionSet) {
writeBuiltinType(typeId, ((OptionSetUInteger<?>) value).getValue());
} else {
writeBuiltinType(typeId, value);
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -27,4 +27,8 @@ default ExpandedNodeId getXmlEncodingId() {
return ExpandedNodeId.NULL_VALUE;
}

default ExpandedNodeId getJsonEncodingId() {
return ExpandedNodeId.NULL_VALUE;
}

}

Large diffs are not rendered by default.

@@ -0,0 +1,118 @@
/*
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.milo.opcua.stack.core.types.builtin;

import java.util.Collection;
import java.util.Set;

import org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UNumber;

public abstract class OptionSetUInteger<F extends Enum<F> & OptionSetUInteger.BitIndex> extends UNumber {

protected final UNumber value;

public OptionSetUInteger(UNumber value) {
this.value = value;
}

public UNumber getValue() {
return value;
}

@Override
public final int intValue() {
return value.intValue();
}

@Override
public final long longValue() {
return value.longValue();
}

@Override
public final float floatValue() {
return value.floatValue();
}

@Override
public final double doubleValue() {
return value.doubleValue();
}

/**
* Returns the value of the bit at {@code field}'s index.
*
* @param field the field
* @return {@code true} if the bit at {@code field}'s index is set.
*/
public final boolean get(F field) {
return get(field.getBitIndex());
}

/**
* Returns the value of the bit at {@code bitIndex}.
*
* @param bitIndex the bit index.
* @return {@code true} if the bit at {@code bitIndex} is set.
*/
public final boolean get(int bitIndex) {
return ((longValue() >>> bitIndex) & 1) == 1;
}

/**
* Check if all bit {@code fields} are set.
*
* @param fields the fields to check.
* @return {@code true} if all bit {@code fields} are set.
*/
@SafeVarargs
public final boolean containsAll(F... fields) {
boolean b = true;
for (F f : fields) {
b &= get(f);
}
return b;
}

/**
* Check if all bit {@code fields} are set.
*
* @param fields the fields to check.
* @return {@code true} if all bit {@code fields} are set.
*/
public final boolean containsAll(Collection<F> fields) {
boolean b = true;
for (F f : fields) {
b &= get(f);
}
return b;
}

/**
* Get the {@link Set} of fields that have their bit set.
*
* @return the {@link Set} of fields that have their bit set.
*/
public abstract Set<F> toSet();

/**
* Identifiers a type that has a corresponding bit index.
*/
public interface BitIndex {

/**
* @return the index of some bit that corresponds with this type.
*/
int getBitIndex();

}

}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -83,6 +83,19 @@ public static UShort valueOf(int value) throws NumberFormatException {
return new UShort(value);
}

/**
* Create an <code>unsigned short</code>
*
* @throws NumberFormatException If <code>value</code> is not in the range
* of an <code>unsigned short</code>
*/
public static UShort valueOf(long value) throws NumberFormatException {
if (value < MIN_VALUE || value > MAX_VALUE) {
throw new NumberFormatException("Value is out of range : " + value);
}
return new UShort((int) value);
}

/**
* Create an <code>unsigned short</code>
*
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down
@@ -0,0 +1,82 @@
/*
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*/

package org.eclipse.milo.opcua.stack.core.types.enumerated;

import org.eclipse.milo.opcua.stack.core.serialization.SerializationContext;
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.UaEnumeration;
import org.eclipse.milo.opcua.stack.core.serialization.codecs.GenericDataTypeCodec;
import org.eclipse.milo.opcua.stack.core.types.builtin.ExpandedNodeId;
import org.jetbrains.annotations.Nullable;

public enum BrokerTransportQualityOfService implements UaEnumeration {
NotSpecified(0),

BestEffort(1),

AtLeastOnce(2),

AtMostOnce(3),

ExactlyOnce(4);

private final int value;

BrokerTransportQualityOfService(int value) {
this.value = value;
}

@Override
public int getValue() {
return value;
}

@Nullable
public static BrokerTransportQualityOfService from(int value) {
switch (value) {
case 0:
return NotSpecified;
case 1:
return BestEffort;
case 2:
return AtLeastOnce;
case 3:
return AtMostOnce;
case 4:
return ExactlyOnce;
default:
return null;
}
}

public static ExpandedNodeId getTypeId() {
return ExpandedNodeId.parse("nsu=http://opcfoundation.org/UA/;i=15008");
}

public static class Codec extends GenericDataTypeCodec<BrokerTransportQualityOfService> {
@Override
public Class<BrokerTransportQualityOfService> getType() {
return BrokerTransportQualityOfService.class;
}

@Override
public BrokerTransportQualityOfService decode(SerializationContext context, UaDecoder decoder) {
return decoder.readEnum(null, BrokerTransportQualityOfService.class);
}

@Override
public void encode(SerializationContext context, UaEncoder encoder,
BrokerTransportQualityOfService value) {
encoder.writeEnum(null, value);
}
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019 the Eclipse Milo Authors
* Copyright (c) 2021 the Eclipse Milo Authors
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down

0 comments on commit a8b80b9

Please sign in to comment.