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.controller.cluster.datastore.node.utils.stream;
10 import java.io.DataInput;
11 import java.io.IOException;
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.opendaylight.yangtools.yang.common.QName;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
17 final class SodiumNormalizedNodeInputStreamReader extends LithiumNormalizedNodeInputStreamReader {
18 private final List<AugmentationIdentifier> codedAugments = new ArrayList<>();
19 private final List<QName> codedQNames = new ArrayList<>();
21 SodiumNormalizedNodeInputStreamReader(final DataInput input) {
26 public NormalizedNodeStreamVersion getVersion() throws IOException {
27 return NormalizedNodeStreamVersion.SODIUM;
31 QName readQName() throws IOException {
32 final byte valueType = readByte();
34 case TokenTypes.IS_QNAME_CODE:
35 return codedQName(readInt());
36 case TokenTypes.IS_QNAME_VALUE:
39 throw new IOException("Unhandled QName value type " + valueType);
44 AugmentationIdentifier readAugmentationIdentifier() throws IOException {
45 final byte valueType = readByte();
47 case TokenTypes.IS_AUGMENT_CODE:
48 return codecAugmentId(readInt());
49 case TokenTypes.IS_AUGMENT_VALUE:
50 return rawAugmentId();
52 throw new IOException("Unhandled QName value type " + valueType);
56 private QName codedQName(final int code) throws IOException {
58 return codedQNames.get(code);
59 } catch (IndexOutOfBoundsException e) {
60 throw new IOException("QName code " + code + " was not found", e);
64 private QName rawQName() throws IOException {
65 final QName qname = super.readQName();
66 codedQNames.add(qname);
70 private AugmentationIdentifier codecAugmentId(final int code) throws IOException {
72 return codedAugments.get(code);
73 } catch (IndexOutOfBoundsException e) {
74 throw new IOException("QName set code " + code + " was not found", e);
78 private AugmentationIdentifier rawAugmentId() throws IOException {
79 final AugmentationIdentifier aid = super.readAugmentationIdentifier();
80 codedAugments.add(aid);