Codec

Codec class is part of YDK path API, which operates on generic path-based YANG data nodes.

class ydk::path::Codec
virtual std::string encode(const std::unique_ptr<DataNode> datanode, EncodingFormat format, bool pretty)

Encode the given DataNode Tree.

Parameters:
  • datanode – The DataNode to encode.
  • format – format to encode to, either JSON or XML.
  • pretty – The output is indented for human consumption, if pretty is true.
Returns:

The encoded string.

Raises:

YInvalidArgumentError, if errors appear during encoding.

virtual std::string encode(std::vector<DataNode *> data_nodes, EncodingFormat format, bool pretty)

Encode multiple DataNodes.

Parameters:
  • data_nodes – An instance of std::vector<DataNode*> class, which contains one or more data nodes.
  • format – format to encode to, either JSON or XML.
  • pretty – The output is indented for human consumption. if pretty is true.
Returns:

The encoded string.

Raises:

YInvalidArgumentError, errors appear during encoding.

std::shared_ptr<DataNode> decode(const RootSchemaNode &root_schema, const std::string &payload, Format format)

Decode the buffer to return a DataNode.

Parameters:
  • root_schema – The root schema to use.
  • payload – The string representation of the DataNode.
  • format – Format of the payload: either JSON or XML.
Returns:

The DataNode instance or nullptr in case of error.

Raises:

YInvalidArgumentError, if errors appear during decoding.

std::shared_ptr<DataNode> decode_rpc_output(RootSchemaNode &root_schema, const std::string &payload, const std::string &rpc_path, EncodingFormat format)

Decode the rpc output to return a DataNode.

Parameters:
  • root_schema – The root schema to use.
  • payload – String representation of one or multiple DataNode.
  • format – Format of the payload: either JSON or XML.
Returns:

The DataNode instance or nullptr in case of error.

Raises:

YInvalidArgumentError, if errors appear during decoding.