Clean up public entrypoints
[yangtools.git] / yang / yang-data-codec-binfmt / src / main / java / org / opendaylight / yangtools / yang / data / codec / binfmt / NormalizedNodeStreamVersion.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.yang.data.codec.binfmt;
9
10 import com.google.common.annotations.Beta;
11 import java.io.DataOutput;
12 import java.math.BigInteger;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
14 import org.opendaylight.yangtools.yang.common.Uint64;
15 import org.opendaylight.yangtools.yang.data.api.schema.ValueNode;
16
17 /**
18  * Enumeration of all stream versions this implementation supports on both input and output.
19  */
20 @Beta
21 @NonNullByDefault
22 public enum NormalizedNodeStreamVersion {
23     /**
24      * Original stream version, as shipped in OpenDaylight Lithium simultaneous release. The caveat here is that this
25      * version has augmented in OpenDaylight Oxygen to retrofit a non-null representation of the empty type.
26      */
27     // FIXME: 5.0.0: consider deprecating this version
28     LITHIUM {
29         @Override
30         public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
31             return new LithiumNormalizedNodeOutputStreamWriter(output);
32         }
33     },
34     /**
35      * Updated stream version, as shipped in OpenDaylight Neon SR2 release. Improves identifier encoding over
36      * {@link #LITHIUM}, so that QName caching is more effective.
37      */
38     NEON_SR2 {
39         @Override
40         public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
41             return new NeonSR2NormalizedNodeOutputStreamWriter(output);
42         }
43     },
44     /**
45      * First shipping in Sodium SR1. Improved stream coding to eliminate redundancies present in {@link #NEON_SR2}.
46      * Supports {code Uint8} et al. as well as {@link BigInteger}.
47      */
48     SODIUM_SR1 {
49         @Override
50         public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
51             return new SodiumSR1DataOutput(output);
52         }
53     },
54     /**
55      * First shipping is Magnesium. Does not support {@link BigInteger} mirroring it being superseded by {@link Uint64}
56      * in {@link ValueNode#getValue()}.
57      */
58     MAGNESIUM {
59         @Override
60         public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
61             return new MagnesiumDataOutput(output);
62         }
63     };
64
65     /**
66      * Return the current runtime version. Guaranteed to not throw {@link UnsupportedOperationException} from
67      * {@link #newDataOutput(DataOutput)}.
68      *
69      * @return Current runtime version.
70      */
71     public static NormalizedNodeStreamVersion current() {
72         return MAGNESIUM;
73     }
74
75     /**
76      * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output.
77      *
78      * @param output the DataOutput to write to
79      * @return a new {@link NormalizedNodeDataOutput} instance
80      * @throws NullPointerException if {@code output} is null
81      * @throws UnsupportedOperationException if this version cannot be created in this runtime
82      */
83     public abstract NormalizedNodeDataOutput newDataOutput(DataOutput output);
84 }