2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.codec.binfmt;
10 import static java.util.Objects.requireNonNull;
12 import com.google.common.collect.ImmutableList;
13 import com.google.common.collect.ImmutableList.Builder;
14 import java.io.DataInput;
15 import java.io.IOException;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.opendaylight.yangtools.yang.common.QName;
18 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
19 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier;
20 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
21 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Descendant;
23 abstract class AbstractNormalizedNodeDataInput extends ForwardingDataInput implements NormalizedNodeDataInput {
24 // Visible for subclasses
25 final @NonNull DataInput input;
27 AbstractNormalizedNodeDataInput(final DataInput input) {
28 this.input = requireNonNull(input);
32 final DataInput delegate() {
38 public final SchemaPath readSchemaPath() throws IOException {
39 final boolean absolute = input.readBoolean();
40 return SchemaPath.create(readQNames(), absolute);
44 public final SchemaNodeIdentifier readSchemaNodeIdentifier() throws IOException {
45 final boolean absolute = input.readBoolean();
46 final ImmutableList<QName> qnames = readQNames();
47 return absolute ? Absolute.of(qnames) : Descendant.of(qnames);
50 private ImmutableList<QName> readQNames() throws IOException {
51 final int size = input.readInt();
52 final Builder<QName> qnames = ImmutableList.builderWithExpectedSize(size);
53 for (int i = 0; i < size; ++i) {
54 qnames.add(readQName());
56 return qnames.build();