nlib
nn::nlib::msgpack::JsonPatchBuilder Class Referencefinal

Class to create JSON Patch (RFC-6902). More...

#include "nn/nlib/msgpack/JsonPatch.h"

Public Member Functions

errno_t Add (const nlib_utf8_t *path, MpObject *value) noexcept
 Adds an "add" operation to the array that serves as the JSON Patch document. More...
 
errno_t Remove (const nlib_utf8_t *path) noexcept
 Adds a "remove" operation to the array that serves as the JSON Patch document. More...
 
errno_t Move (const nlib_utf8_t *path, const nlib_utf8_t *from) noexcept
 Adds a "move" operation to the array that serves as the JSON Patch document. More...
 
errno_t Copy (const nlib_utf8_t *path, const nlib_utf8_t *from) noexcept
 Adds a "copy" operation to the array that serves as the JSON Patch document. More...
 
errno_t Test (const nlib_utf8_t *path, MpObject *value) noexcept
 Adds a "test" operation to the array that serves as the JSON Patch document. More...
 
errno_t Export (MpObject *patch) noexcept
 Retrieves a JSON document that serves as JSON Patch. More...
 
Basic Member Functions
 JsonPatchBuilder () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~JsonPatchBuilder () noexcept
 Destructor.
 

Detailed Description

Class to create JSON Patch (RFC-6902).

Description
Instantiates the object and then constructs a JSON Patch document using Add(), Remove(), Replace(), Move(), Copy(), or Test(). Each of these member functions corresponds to the "add," "remove," "replace," "move," "copy," or "test" operation defined in RFC-6902. When the JSON Patch document has been constructed, it is output as MpObject using Export(). The output JSON Patch document can be applied using JsonPatch::Apply().
See also
https://tools.ietf.org/html/rfc6902
https://triple-underscore.github.io/RFC6902-ja.html

Definition at line 30 of file JsonPatch.h.

Member Function Documentation

◆ Add()

nn::nlib::msgpack::JsonPatchBuilder::Add ( const nlib_utf8_t path,
MpObject value 
)
inlinenoexcept

Adds an "add" operation to the array that serves as the JSON Patch document.

Parameters
[in]pathA JSON Pointer string that indicates a location where value is set in the JSON document.
[in]valueThe value being set.
Return values
0Success.
ENOMEMIndicates that the memory allocation has failed.
Description
The "add" operation performs one of the following operations on the location indicated by path in the JSON document.
  • If path is an empty string, the entire JSON document is replaced with value.
  • If path indicates an array index, new value is inserted into the position of that index. If the end of the array is '-,' value is appended to the array end.
  • If no key is found at the end of path, value is appended to that end as a value referenced as the key.
  • If a value that serves as the key for path has been found, that value is replaced with value.

Definition at line 52 of file JsonPatch.h.

◆ Copy()

nn::nlib::msgpack::JsonPatchBuilder::Copy ( const nlib_utf8_t path,
const nlib_utf8_t from 
)
inlinenoexcept

Adds a "copy" operation to the array that serves as the JSON Patch document.

Parameters
[in]pathA JSON Pointer string that indicates a location to copy to in the JSON document.
[in]fromA JSON Pointer string that indicates a location to copy from in the JSON document.
Return values
0Success.
ENOMEMIndicates that the memory allocation has failed.
Description
The "copy" operation is equivalent to an operation where an "add" operation appends a value specified by from by specifying path. The location from represents needs to be described in the target JSON document before doing this operation.

Definition at line 63 of file JsonPatch.h.

◆ Export()

nn::nlib::msgpack::JsonPatchBuilder::Export ( MpObject patch)
noexcept

Retrieves a JSON document that serves as JSON Patch.

Parameters
[in]patchMpObject that contains the JSON document that serves as JSON Patch.
Return values
0Success.
ENOMEMIndicates that the memory allocation has failed.
Description
The retrieved JSON Patch document is stored in patch. The data stored in patch is deleted, and JsonPatchBuilder is set to the same state as when immediately after the constructor was executed. ENOMEM may be returned only when no operation has been added.

◆ Move()

nn::nlib::msgpack::JsonPatchBuilder::Move ( const nlib_utf8_t path,
const nlib_utf8_t from 
)
inlinenoexcept

Adds a "move" operation to the array that serves as the JSON Patch document.

Parameters
[in]pathA JSON Pointer string that indicates a location to move to in the JSON document.
[in]fromA JSON Pointer string that indicates a location to move from in the JSON document.
Return values
0Success.
ENOMEMIndicates that the memory allocation has failed.
Description
The "move" operation is equivalent to a set of operations where a "remove" operation removes a value by specifying from and then an "add" operation appends that value by specifying path. The location from represents needs to be described in the target JSON document before doing this operation.

Definition at line 59 of file JsonPatch.h.

◆ Remove()

nn::nlib::msgpack::JsonPatchBuilder::Remove ( const nlib_utf8_t path)
noexcept

Adds a "remove" operation to the array that serves as the JSON Patch document.

Parameters
[in]pathA JSON Pointer string that indicates a location to be deleted in the JSON document.
Return values
0Success.
ENOMEMIndicates that the memory allocation has failed.
Description
The "remove" operation deletes the location indicated by path in the JSON document. The location path represents needs to be described in the target JSON document before doing this operation. The details are as follows:
  • If path is an empty string, the entire JSON document is deleted.
  • If path indicates an array index, elements before the specified index are moved forward one by one.
  • Otherwise, the value specified by path and the key that directly indicates that value are removed.

◆ Test()

nn::nlib::msgpack::JsonPatchBuilder::Test ( const nlib_utf8_t path,
MpObject value 
)
inlinenoexcept

Adds a "test" operation to the array that serves as the JSON Patch document.

Parameters
[in]pathA JSON Pointer string that indicates a location where an operation is performed in the JSON document.
[in]valueA value to be compared.
Return values
0Success.
ENOMEMIndicates that the memory allocation has failed.
Description
The "test" operation compares the value specified by path with value. When the both values are equivalent in terms of JSON, the "test" operation is evaluated for success.

Definition at line 67 of file JsonPatch.h.


The documentation for this class was generated from the following files: