private static final byte @NonNull[] BINARY_0 = new byte[0];
private static final @NonNull AugmentationIdentifier EMPTY_AID = AugmentationIdentifier.create(ImmutableSet.of());
- // FIXME: these should be available as constants
- private static final @NonNull Uint8 UINT8_0 = Uint8.valueOf(0);
- private static final @NonNull Uint16 UINT16_0 = Uint16.valueOf(0);
- private static final @NonNull Uint32 UINT32_0 = Uint32.valueOf(0);
- private static final @NonNull Uint64 UINT64_0 = Uint64.valueOf(0);
-
private final List<AugmentationIdentifier> codedAugments = new ArrayList<>();
private final List<NodeIdentifier> codedNodeIdentifiers = new ArrayList<>();
private final List<QNameModule> codedModules = new ArrayList<>();
case MagnesiumValue.UINT8:
return Uint8.fromByteBits(input.readByte());
case MagnesiumValue.UINT8_0:
- return UINT8_0;
+ return Uint8.ZERO;
case MagnesiumValue.UINT16:
return Uint16.fromShortBits(input.readShort());
case MagnesiumValue.UINT16_0:
- return UINT16_0;
+ return Uint16.ZERO;
case MagnesiumValue.UINT32:
return Uint32.fromIntBits(input.readInt());
case MagnesiumValue.UINT32_0:
- return UINT32_0;
+ return Uint32.ZERO;
case MagnesiumValue.UINT32_2B:
return Uint32.fromIntBits(input.readShort() & 0xFFFF);
case MagnesiumValue.UINT64:
return Uint64.fromLongBits(input.readLong());
case MagnesiumValue.UINT64_0:
- return UINT64_0;
+ return Uint64.ZERO;
case MagnesiumValue.UINT64_4B:
return Uint64.fromLongBits(input.readInt() & 0xFFFFFFFFL);
case MagnesiumValue.BIGDECIMAL:
default Optional<NormalizedNode<?, ?>> readOptionalNormalizedNode() throws IOException {
return readBoolean() ? Optional.of(readNormalizedNode()) : Optional.empty();
}
+
+ /**
+ * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method first reads
+ * and validates that the input contains a valid NormalizedNode stream.
+ *
+ * @param input the DataInput to read from
+ * @return a new {@link NormalizedNodeDataInput} instance
+ * @throws InvalidNormalizedNodeStreamException if the stream version is not supported
+ * @throws IOException if an error occurs reading from the input
+ */
+ static @NonNull NormalizedNodeDataInput newDataInput(final @NonNull DataInput input) throws IOException {
+ return new VersionedNormalizedNodeDataInput(input).delegate();
+ }
+
+ /**
+ * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method does not
+ * perform any initial validation of the input stream.
+ *
+ * @param input the DataInput to read from
+ * @return a new {@link NormalizedNodeDataInput} instance
+ * @deprecated Use {@link #newDataInput(DataInput)} instead.
+ */
+ // FIXME: 5.0.0: deprecate for removal
+ @Deprecated
+ static @NonNull NormalizedNodeDataInput newDataInputWithoutValidation(final @NonNull DataInput input) {
+ return new VersionedNormalizedNodeDataInput(input);
+ }
}
import com.google.common.annotations.Beta;
import java.io.DataOutput;
import java.io.IOException;
-import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
* and {@link SchemaPath}s.
*/
@Beta
+@NonNullByDefault
public interface NormalizedNodeDataOutput extends AutoCloseable, DataOutput {
- void writeQName(@NonNull QName qname) throws IOException;
+ void writeQName(QName qname) throws IOException;
- void writeNormalizedNode(@NonNull NormalizedNode<?, ?> normalizedNode) throws IOException;
+ void writeNormalizedNode(NormalizedNode<?, ?> normalizedNode) throws IOException;
void writePathArgument(PathArgument pathArgument) throws IOException;
+++ /dev/null
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.yangtools.yang.data.codec.binfmt;
-
-import com.google.common.annotations.Beta;
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.IOException;
-import org.eclipse.jdt.annotation.NonNull;
-
-@Beta
-public final class NormalizedNodeInputOutput {
- private NormalizedNodeInputOutput() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method first reads
- * and validates that the input contains a valid NormalizedNode stream.
- *
- * @param input the DataInput to read from
- * @return a new {@link NormalizedNodeDataInput} instance
- * @throws IOException if an error occurs reading from the input
- */
- public static NormalizedNodeDataInput newDataInput(final @NonNull DataInput input) throws IOException {
- return new VersionedNormalizedNodeDataInput(input).delegate();
- }
-
- /**
- * Creates a new {@link NormalizedNodeDataInput} instance that reads from the given input. This method does not
- * perform any initial validation of the input stream.
- *
- * @param input the DataInput to read from
- * @return a new {@link NormalizedNodeDataInput} instance
- */
- public static NormalizedNodeDataInput newDataInputWithoutValidation(final @NonNull DataInput input) {
- return new VersionedNormalizedNodeDataInput(input);
- }
-
- /**
- * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output and latest current
- * stream version.
- *
- * @param output the DataOutput to write to
- * @return a new {@link NormalizedNodeDataOutput} instance
- */
- public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output) {
- return new SodiumSR1DataOutput(output);
- }
-
- /**
- * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output.
- *
- * @param output the DataOutput to write to
- * @param version Streaming version to use
- * @return a new {@link NormalizedNodeDataOutput} instance
- */
- public static NormalizedNodeDataOutput newDataOutput(final @NonNull DataOutput output,
- final @NonNull NormalizedNodeStreamVersion version) {
- switch (version) {
- case LITHIUM:
- return new LithiumNormalizedNodeOutputStreamWriter(output);
- case NEON_SR2:
- return new NeonSR2NormalizedNodeOutputStreamWriter(output);
- case SODIUM_SR1:
- return new SodiumSR1DataOutput(output);
- case MAGNESIUM:
- return new MagnesiumDataOutput(output);
- default:
- throw new IllegalStateException("Unhandled version " + version);
- }
- }
-
-}
package org.opendaylight.yangtools.yang.data.codec.binfmt;
import com.google.common.annotations.Beta;
+import java.io.DataOutput;
+import java.math.BigInteger;
import org.eclipse.jdt.annotation.NonNullByDefault;
+import org.opendaylight.yangtools.yang.common.Uint64;
+import org.opendaylight.yangtools.yang.data.api.schema.ValueNode;
/**
* Enumeration of all stream versions this implementation supports on both input and output.
@Beta
@NonNullByDefault
public enum NormalizedNodeStreamVersion {
- LITHIUM,
- NEON_SR2,
- SODIUM_SR1,
- MAGNESIUM;
+ /**
+ * Original stream version, as shipped in OpenDaylight Lithium simultaneous release. The caveat here is that this
+ * version has augmented in OpenDaylight Oxygen to retrofit a non-null representation of the empty type.
+ */
+ // FIXME: 5.0.0: consider deprecating this version
+ LITHIUM {
+ @Override
+ public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
+ return new LithiumNormalizedNodeOutputStreamWriter(output);
+ }
+ },
+ /**
+ * Updated stream version, as shipped in OpenDaylight Neon SR2 release. Improves identifier encoding over
+ * {@link #LITHIUM}, so that QName caching is more effective.
+ */
+ NEON_SR2 {
+ @Override
+ public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
+ return new NeonSR2NormalizedNodeOutputStreamWriter(output);
+ }
+ },
+ /**
+ * First shipping in Sodium SR1. Improved stream coding to eliminate redundancies present in {@link #NEON_SR2}.
+ * Supports {code Uint8} et al. as well as {@link BigInteger}.
+ */
+ SODIUM_SR1 {
+ @Override
+ public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
+ return new SodiumSR1DataOutput(output);
+ }
+ },
+ /**
+ * First shipping is Magnesium. Does not support {@link BigInteger} mirroring it being superseded by {@link Uint64}
+ * in {@link ValueNode#getValue()}.
+ */
+ MAGNESIUM {
+ @Override
+ public NormalizedNodeDataOutput newDataOutput(DataOutput output) {
+ return new MagnesiumDataOutput(output);
+ }
+ };
+
+ /**
+ * Return the current runtime version. Guaranteed to not throw {@link UnsupportedOperationException} from
+ * {@link #newDataOutput(DataOutput)}.
+ *
+ * @return Current runtime version.
+ */
+ public static NormalizedNodeStreamVersion current() {
+ return MAGNESIUM;
+ }
+
+ /**
+ * Creates a new {@link NormalizedNodeDataOutput} instance that writes to the given output.
+ *
+ * @param output the DataOutput to write to
+ * @return a new {@link NormalizedNodeDataOutput} instance
+ * @throws NullPointerException if {@code output} is null
+ * @throws UnsupportedOperationException if this version cannot be created in this runtime
+ */
+ public abstract NormalizedNodeDataOutput newDataOutput(DataOutput output);
}