import java.io.IOException;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.concepts.WritableObject;
+import org.opendaylight.yangtools.yang.data.codec.binfmt.NormalizedNodeStreamVersion;
/**
* Enumeration of all ABI versions supported by this implementation of persistence. An ABI version has to be bumped
*/
@Beta
public enum PayloadVersion implements WritableObject {
- // NOTE: enumeration values need to be sorted in asceding order of their version to keep Comparable working
+ // NOTE: enumeration values need to be sorted in ascending order of their version to keep Comparable working
/**
* Version which is older than any other version. This version exists purely for testing purposes.
*/
@VisibleForTesting
- TEST_PAST_VERSION(0),
+ TEST_PAST_VERSION(0) {
+ @Override
+ public NormalizedNodeStreamVersion getStreamVersion() {
+ throw new UnsupportedOperationException();
+ }
+ },
/**
- * Initial ABI version, as shipped with Boron Simultaneous release.
+ * ABI version as shipped in Sodium SR1 Simultaneous Release. QName-bearing messages are using
+ * {@link NormalizedNodeStreamVersion#SODIUM_SR1}, which improves encoding.
*/
- // We seed the initial version to be the same as DataStoreVersions.BORON-VERSION for compatibility reasons.
- BORON(5),
+ SODIUM_SR1(7) {
+ @Override
+ public NormalizedNodeStreamVersion getStreamVersion() {
+ return NormalizedNodeStreamVersion.SODIUM_SR1;
+ }
+ },
+
+ /**
+ * Revised payload version. Payloads remain the same as {@link #SODIUM_SR1}, but messages bearing QNames in any
+ * shape are using {@link NormalizedNodeStreamVersion#MAGNESIUM}, which improves encoding.
+ */
+ MAGNESIUM(8) {
+ @Override
+ public NormalizedNodeStreamVersion getStreamVersion() {
+ return NormalizedNodeStreamVersion.MAGNESIUM;
+ }
+ },
/**
* Version which is newer than any other version. This version exists purely for testing purposes.
*/
@VisibleForTesting
- TEST_FUTURE_VERSION(65535);
+ TEST_FUTURE_VERSION(65535) {
+ @Override
+ public NormalizedNodeStreamVersion getStreamVersion() {
+ throw new UnsupportedOperationException();
+ }
+ };
private final short value;
return value;
}
+ /**
+ * Return the NormalizedNode stream version corresponding to this particular ABI.
+ *
+ * @return Stream Version to use for this ABI version
+ */
+ public abstract @NonNull NormalizedNodeStreamVersion getStreamVersion();
+
/**
* Return the codebase-native persistence version. This version is the default version allocated to messages
* at runtime. Conversion to previous versions may incur additional overhead (such as object allocation).
* @return Current {@link PayloadVersion}
*/
public static @NonNull PayloadVersion current() {
- return BORON;
+ return MAGNESIUM;
}
/**
*/
public static @NonNull PayloadVersion valueOf(final short version)
throws FutureVersionException, PastVersionException {
- switch (Short.toUnsignedInt(version)) {
- case 0:
- case 1:
- case 2:
- case 3:
- case 4:
- throw new PastVersionException(version, BORON);
- case 5:
- return BORON;
- default:
- throw new FutureVersionException(version, BORON);
- }
+ return switch (Short.toUnsignedInt(version)) {
+ case 0, 1, 2, 3, 4, 5, 6 -> throw new PastVersionException(version, SODIUM_SR1);
+ case 7 -> SODIUM_SR1;
+ case 8 -> MAGNESIUM;
+ default -> throw new FutureVersionException(version, MAGNESIUM);
+ };
}
@Override
try {
return valueOf(s);
} catch (FutureVersionException | PastVersionException e) {
- throw new IOException("Unsupported version", e);
+ throw new IOException(e);
}
}
-
}