From: Robert Varga Date: Wed, 3 Jul 2019 22:37:53 +0000 (+0200) Subject: Make LogicalDatastoreType a WritableObject X-Git-Tag: v3.0.10~3 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F23%2F82923%2F1;p=mdsal.git Make LogicalDatastoreType a WritableObject This is a low-cardinality enum, which we need to serialize quite often. Make it a simple WritableObject, so users can get common handling. One specific user is sal-remoterpc-connector, which needs to be able to serialize DOMDataTreeIdentifier. JIRA: CONTROLLER-1894 Change-Id: Iee4610e093639629039a2e21ab1cfc852b756169 Signed-off-by: Robert Varga (cherry picked from commit b0c200e4da8fced37726872197c510766a7ed4fd) --- diff --git a/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/LogicalDatastoreType.java b/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/LogicalDatastoreType.java index 31016717bc..928b27d30b 100644 --- a/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/LogicalDatastoreType.java +++ b/common/mdsal-common-api/src/main/java/org/opendaylight/mdsal/common/api/LogicalDatastoreType.java @@ -7,12 +7,18 @@ */ package org.opendaylight.mdsal.common.api; +import java.io.DataInput; +import java.io.DataOutput; +import java.io.IOException; +import org.eclipse.jdt.annotation.NonNull; +import org.opendaylight.yangtools.concepts.WritableObject; + /** * The concept of a logical data store, similar to RFC8342. */ // FIXME: 3.0.0: turn this into an interface so it can be externally-defined? // FIXME: 3.0.0: note that mount points can have different types and policies, which can potentially be mapped -public enum LogicalDatastoreType { +public enum LogicalDatastoreType implements WritableObject { /** * Logical datastore representing operational state of the system and it's components. This datastore is used * to describe operational state of the system and it's operation related data. @@ -26,7 +32,7 @@ public enum LogicalDatastoreType { * * */ - OPERATIONAL, + OPERATIONAL(1), /** * Logical Datastore representing configuration state of the system and it's components. This datastore is used * to describe intended state of the system and intended operation mode. @@ -43,5 +49,28 @@ public enum LogicalDatastoreType { * * */ - CONFIGURATION + CONFIGURATION(2); + + private int serialized; + + LogicalDatastoreType(final int serialized) { + this.serialized = serialized; + } + + @Override + public void writeTo(final DataOutput out) throws IOException { + out.writeByte(serialized); + } + + public static @NonNull LogicalDatastoreType readFrom(final DataInput in) throws IOException { + final byte serialized = in.readByte(); + switch (serialized) { + case 1: + return OPERATIONAL; + case 2: + return CONFIGURATION; + default: + throw new IOException("Unknown type " + serialized); + } + } }