/* * Copyright 2015 Kevin Herron * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.digitalpetri.opcua.stack.core.types.enumerated; import com.digitalpetri.opcua.stack.core.serialization.DelegateRegistry; import com.digitalpetri.opcua.stack.core.serialization.UaDecoder; import com.digitalpetri.opcua.stack.core.serialization.UaEncoder; import com.digitalpetri.opcua.stack.core.serialization.UaEnumeration; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; public enum NodeClass implements UaEnumeration { Unspecified(0), Object(1), Variable(2), Method(4), ObjectType(8), VariableType(16), ReferenceType(32), DataType(64), View(128); private final int value; NodeClass(int value) { this.value = value; } @Override public int getValue() { return value; } private static final ImmutableMap<Integer, NodeClass> VALUES; static { Builder<Integer, NodeClass> builder = ImmutableMap.builder(); for (NodeClass e : values()) { builder.put(e.getValue(), e); } VALUES = builder.build(); } public static NodeClass from(Integer value) { if (value == null) return null; return VALUES.getOrDefault(value, null); } public static void encode(NodeClass nodeClass, UaEncoder encoder) { encoder.encodeInt32(null, nodeClass.getValue()); } public static NodeClass decode(UaDecoder decoder) { int value = decoder.decodeInt32(null); return VALUES.getOrDefault(value, null); } static { DelegateRegistry.registerEncoder(NodeClass::encode, NodeClass.class); DelegateRegistry.registerDecoder(NodeClass::decode, NodeClass.class); } }