As we are going to introduce a streaming format for Magnesium, which
uses very different token set, it is convenient to have a common
base class which does not have conotations about what the tokens are.
We provide a baseline counterpart to AbstractNormalizedNodeDataOutput
and base AbstractLithiumDataInput on it. The asymmetry of
writeYangInstanceIdentifier() is fixed by moving it to
AbstractLithiumDataOutput.
Change-Id: I55d318349f2c89508f3834c8ca5b69e69b7171b1
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit
ad7135c49d0ec5f7180b46fe3657349c5d81bc63)
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.dom.DOMSource;
-import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.controller.cluster.datastore.node.utils.QNameFactory;
import org.opendaylight.yangtools.util.ImmutableOffsetMapTemplate;
import org.opendaylight.yangtools.yang.common.Empty;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Element;
* nodes. This process goes in recursive manner, where each NodeTypes object signifies the start of the object, except
* END_NODE. If a node can have children, then that node's end is calculated based on appearance of END_NODE.
*/
-abstract class AbstractLithiumDataInput extends ForwardingDataInput implements NormalizedNodeDataInput {
+abstract class AbstractLithiumDataInput extends AbstractNormalizedNodeDataInput {
private static final Logger LOG = LoggerFactory.getLogger(AbstractLithiumDataInput.class);
- private final @NonNull DataInput input;
-
private final List<String> codedStringMap = new ArrayList<>();
private QName lastLeafSetQName;
AbstractLithiumDataInput(final DataInput input) {
- this.input = requireNonNull(input);
- }
-
- @Override
- final DataInput delegate() {
- return input;
+ super(input);
}
@Override
return new String(bytes, StandardCharsets.UTF_8);
}
- @Override
- public final SchemaPath readSchemaPath() throws IOException {
- final boolean absolute = input.readBoolean();
- final int size = input.readInt();
-
- final Builder<QName> qnames = ImmutableList.builderWithExpectedSize(size);
- for (int i = 0; i < size; ++i) {
- qnames.add(readQName());
- }
- return SchemaPath.create(qnames.build(), absolute);
- }
-
@Override
public final YangInstanceIdentifier readYangInstanceIdentifier() throws IOException {
return readYangInstanceIdentifierInternal();
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
}
}
+ @Override
+ final void writeYangInstanceIdentifierInternal(final YangInstanceIdentifier identifier) throws IOException {
+ List<PathArgument> pathArguments = identifier.getPathArguments();
+ output.writeInt(pathArguments.size());
+
+ for (PathArgument pathArgument : pathArguments) {
+ writePathArgumentInternal(pathArgument);
+ }
+ }
+
final void defaultWriteAugmentationIdentifier(final @NonNull AugmentationIdentifier aid) throws IOException {
final Set<QName> qnames = aid.getPossibleChildNames();
// Write each child's qname separately, if list is empty send count as 0
--- /dev/null
+/*
+ * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.controller.cluster.datastore.node.utils.stream;
+
+import static java.util.Objects.requireNonNull;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableList.Builder;
+import java.io.DataInput;
+import java.io.IOException;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+abstract class AbstractNormalizedNodeDataInput extends ForwardingDataInput implements NormalizedNodeDataInput {
+ // Visible for subclasses
+ final @NonNull DataInput input;
+
+ AbstractNormalizedNodeDataInput(final DataInput input) {
+ this.input = requireNonNull(input);
+ }
+
+ @Override
+ final DataInput delegate() {
+ return input;
+ }
+
+ @Override
+ public final SchemaPath readSchemaPath() throws IOException {
+ final boolean absolute = input.readBoolean();
+ final int size = input.readInt();
+
+ final Builder<QName> qnames = ImmutableList.builderWithExpectedSize(size);
+ for (int i = 0; i < size; ++i) {
+ qnames.add(readQName());
+ }
+ return SchemaPath.create(qnames.build(), absolute);
+ }
+
+}
}
}
- final void writeYangInstanceIdentifierInternal(final YangInstanceIdentifier identifier) throws IOException {
- List<PathArgument> pathArguments = identifier.getPathArguments();
- output.writeInt(pathArguments.size());
-
- for (PathArgument pathArgument : pathArguments) {
- writePathArgumentInternal(pathArgument);
- }
- }
-
abstract short streamVersion();
abstract void writeQNameInternal(@NonNull QName qname) throws IOException;
abstract void writePathArgumentInternal(PathArgument pathArgument) throws IOException;
+
+ abstract void writeYangInstanceIdentifierInternal(YangInstanceIdentifier identifier) throws IOException;
}