/** * Serialize a NormalizedNode into a protocol buffer message * <p> * The significant things to be aware of the Serialization process are * <ul> * <li>Repeated strings like namespaces, revisions and localNames are * compressed to codes and stored in the top level of the normalized * node protocol buffer message * </li> * <li>All value types are encoded for each leaf value. This is so that * the deSerialization process does not need to use the schema context to * figure out how to decode values * </li> * </ul> * * One question which may arise is why not use something like gzip to * compress the protocol buffer message instead of rolling our own * encoding scheme. This has to be explored further as it is a more * general solution. * * @param node * @return */ public static NormalizedNodeMessages.Node serialize(final NormalizedNode<?, ?> node){ Preconditions.checkNotNull(node, "node should not be null"); return new Serializer(node).serialize(); }
public Encoded encode(YangInstanceIdentifier path, NormalizedNode<?,?> node) { NormalizedNodeMessages.InstanceIdentifier serializedPath = null; NormalizedNodeMessages.Container.Builder builder = NormalizedNodeMessages.Container.newBuilder(); // Note: parent path is no longer used builder.setParentPath(""); if(node != null) { if(path == null) { builder.setNormalizedNode(NormalizedNodeSerializer.serialize(node)); } else { Serializer serializer = NormalizedNodeSerializer.newSerializer(node); builder.setNormalizedNode(serializer.serialize(path)); serializedPath = serializer.getSerializedPath(); } } return new EncodedImpl(builder.build(), serializedPath); }
public NormalizedNodeMessages.Node serialize() { return this.serialize(node).addAllCode(getCodes()).build(); }
public NormalizedNodeMessages.Node serialize(final YangInstanceIdentifier path) { Builder builder = serialize(node); serializedPath = InstanceIdentifierUtils.toSerializable(path, this); return builder.addAllCode(getCodes()).build(); }