-
- private NodeIdentifierWithPredicates readNormalizedNodeWithPredicates() throws IOException {
- final QName qname = readQName();
- final int count = input.readInt();
- switch (count) {
- case 0:
- return NodeIdentifierWithPredicates.of(qname);
- case 1:
- return NodeIdentifierWithPredicates.of(qname, readQName(), readObject());
- default:
- // ImmutableList is used by ImmutableOffsetMapTemplate for lookups, hence we use that.
- final Builder<QName> keys = ImmutableList.builderWithExpectedSize(count);
- final Object[] values = new Object[count];
- for (int i = 0; i < count; i++) {
- keys.add(readQName());
- values[i] = readObject();
- }
-
- return NodeIdentifierWithPredicates.of(qname, ImmutableOffsetMapTemplate.ordered(keys.build())
- .instantiateWithValues(values));
- }
- }
-
- private Object readObject() throws IOException {
- byte objectType = input.readByte();
- switch (objectType) {
- case ValueTypes.BITS_TYPE:
- return readObjSet();
-
- case ValueTypes.BOOL_TYPE:
- return input.readBoolean();
-
- case ValueTypes.BYTE_TYPE:
- return input.readByte();
-
- case ValueTypes.INT_TYPE:
- return input.readInt();
-
- case ValueTypes.LONG_TYPE:
- return input.readLong();
-
- case ValueTypes.QNAME_TYPE:
- return readQName();
-
- case ValueTypes.SHORT_TYPE:
- return input.readShort();
-
- case ValueTypes.STRING_TYPE:
- return input.readUTF();
-
- case ValueTypes.STRING_BYTES_TYPE:
- return readStringBytes();
-
- case ValueTypes.BIG_DECIMAL_TYPE:
- return new BigDecimal(input.readUTF());
-
- case ValueTypes.BIG_INTEGER_TYPE:
- return new BigInteger(input.readUTF());
-
- case ValueTypes.BINARY_TYPE:
- byte[] bytes = new byte[input.readInt()];
- input.readFully(bytes);
- return bytes;
-
- case ValueTypes.YANG_IDENTIFIER_TYPE:
- return readYangInstanceIdentifierInternal();
-
- case ValueTypes.EMPTY_TYPE:
- // Leaf nodes no longer allow null values and thus we no longer emit null values. Previously, the "empty"
- // yang type was represented as null so we translate an incoming null value to Empty. It was possible for
- // a BI user to set a string leaf to null and we're rolling the dice here but the chances for that are
- // very low. We'd have to know the yang type but, even if we did, we can't let a null value pass upstream
- // so we'd have to drop the leaf which might cause other issues.
- case ValueTypes.NULL_TYPE:
- return Empty.getInstance();
-
- default:
- return null;
- }
- }
-
- private String readStringBytes() throws IOException {
- byte[] bytes = new byte[input.readInt()];
- input.readFully(bytes);
- return new String(bytes, StandardCharsets.UTF_8);
- }
-
- @Override
- public 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 YangInstanceIdentifier readYangInstanceIdentifier() throws IOException {
- return readYangInstanceIdentifierInternal();
- }
-
- private YangInstanceIdentifier readYangInstanceIdentifierInternal() throws IOException {
- int size = input.readInt();
- final Builder<PathArgument> pathArguments = ImmutableList.builderWithExpectedSize(size);
- for (int i = 0; i < size; i++) {
- pathArguments.add(readPathArgument());
- }
- return YangInstanceIdentifier.create(pathArguments.build());
- }
-
- private Set<String> readObjSet() throws IOException {
- int count = input.readInt();
- Set<String> children = new HashSet<>(count);
- for (int i = 0; i < count; i++) {
- children.add(readCodedString());
- }
- return children;
- }
-
- @Override
- public PathArgument readPathArgument() throws IOException {
- // read Type
- int type = input.readByte();
-
- switch (type) {
- case PathArgumentTypes.AUGMENTATION_IDENTIFIER:
- return readAugmentationIdentifier();
- case PathArgumentTypes.NODE_IDENTIFIER:
- return readNodeIdentifier();
- case PathArgumentTypes.NODE_IDENTIFIER_WITH_PREDICATES:
- return readNormalizedNodeWithPredicates();
- case PathArgumentTypes.NODE_IDENTIFIER_WITH_VALUE:
- return new NodeWithValue<>(readQName(), readObject());
- default:
- // FIXME: throw hard error
- return null;
- }
- }
-
- @SuppressWarnings("unchecked")
- private ListNodeBuilder<Object, LeafSetEntryNode<Object>> addLeafSetChildren(final QName nodeType,
- final ListNodeBuilder<Object, LeafSetEntryNode<Object>> builder) throws IOException {
-
- LOG.trace("Reading children of leaf set");
-
- lastLeafSetQName = nodeType;
-
- LeafSetEntryNode<Object> child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal();
-
- while (child != null) {
- builder.withChild(child);
- child = (LeafSetEntryNode<Object>)readNormalizedNodeInternal();
- }
- return builder;
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- private NormalizedNodeContainerBuilder addDataContainerChildren(
- final NormalizedNodeContainerBuilder builder) throws IOException {
- LOG.trace("Reading data container (leaf nodes) nodes");
-
- NormalizedNode<?, ?> child = readNormalizedNodeInternal();
-
- while (child != null) {
- builder.addChild(child);
- child = readNormalizedNodeInternal();
- }
- return builder;
- }