nlib
nn::nlib::msgpack::JsonSchemaConverter Class Referencefinal

Converts JSON Schema to a byte-code format available for JsonSchemaValidator. More...

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

Classes

struct  Detail
 If the conversion of JSON Schema has failed, a string representing the location where the conversion has failed is written into a member named path. More...
 

Public Types

enum  Result {
  kOk = 0,
  kInvalidParam,
  kAlreadyInitialized,
  kOutOfMemory,
  kInvalidSchema,
  kFileNotFound,
  kIoError,
  kUriError,
  kBufferSizeNotEnough
}
 The result of the function executed. More...
 

Public Member Functions

Result Convert (const char *uri, Detail *detail) noexcept
 Converts JSON Schema to a format available for JsonSchemaValidator. More...
 
Result Convert (MpObject *schema, Detail *detail) noexcept
 Converts JSON Schema to a format available for JsonSchemaValidator. More...
 
Result Export (size_t *written, nlib_byte_t *buf, size_t bufsize) const noexcept
 Writes JSON Schema converted to byte-code. More...
 
template<size_t N>
Result Export (size_t *written, nlib_byte_t(&buf)[N]) const noexcept
 A template overload of the above function.
 
std::tuple< Result, std::unique_ptr< nlib_byte_t[]>, size_t > Export () const noexcept
 Returns JSON Schema converted into a byte-code. More...
 
Constructor, Destructor, and Initialization
constexpr JsonSchemaConverter () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~JsonSchemaConverter () noexcept
 Destructor.
 
 JsonSchemaConverter (JsonSchemaConverter &&rhs)
 Instantiates the object (move constructor).
 
JsonSchemaConverteroperator= (JsonSchemaConverter &&rhs)
 Move assignment operator.
 
Result Init (const JsonSchemaConverterSettings &settings) noexcept
 Initializes the object. More...
 
Result Init () noexcept
 A parameter omitted version of the above function which passes settings as the default value.
 
void Reset () noexcept
 Resets this object to the state immediately after the default constructor was executed.
 

Detailed Description

Converts JSON Schema to a byte-code format available for JsonSchemaValidator.

Description
For more information on JSON Schema, see the description of JsonSchemaValidator. For information on coding samples, see JsonSchemaValidator::Validate().

Definition at line 70 of file JsonSchema.h.

Member Enumeration Documentation

◆ Result

The result of the function executed.

Enumerator
kOk 

Successfully completed.

kInvalidParam 

Invalid argument.

kAlreadyInitialized 

Already initialized.

kOutOfMemory 

Failed to allocate memory.

kInvalidSchema 

Invalid JSON Schema.

kFileNotFound 

The specified file could not be found.

kIoError 

Failed while reading the file.

kUriError 

An error occurred in processing the URI.

kBufferSizeNotEnough 

Insufficient buffer size.

Definition at line 72 of file JsonSchema.h.

Member Function Documentation

◆ Convert() [1/2]

nn::nlib::msgpack::JsonSchemaConverter::Convert ( const char *  uri,
Detail detail 
)
noexcept

Converts JSON Schema to a format available for JsonSchemaValidator.

Parameters
[in]uriThe absolute URI indicating JSON which should be JSON Schema.
[in]detailIf specifying non-NULL, additional information can be obtained when an error has occurred.
Return values
kOkThe conversion has been successfully completed.
kOutOfMemoryMemory allocation failed.
kInvalidSchemaInvalid schema.
kFileNotFoundThe file to be read could not be found.
kIoErrorReading the file failed.
kUriErrorInvalid URI was found or uri was a relative URI.
Description
Converts JSON Schema referenced with uri. Note that JsonSchemaConverterSettings::uri_mapper is used to convert the URI to the actual file path. If uri is NULL, uri is assumed to be "nlibpath:///jsonschema/schema.json."

◆ Convert() [2/2]

nn::nlib::msgpack::JsonSchemaConverter::Convert ( MpObject schema,
Detail detail 
)
noexcept

Converts JSON Schema to a format available for JsonSchemaValidator.

Parameters
[in,out]schemaThe JSON Schema to be converted. Note that internal values may be changed.
[in]detailIf not specifying NULL, additional information can be obtained when an error has occurred.
Return values
kOkThe conversion has been successfully completed.
kOutOfMemoryMemory allocation failed.
kInvalidParamschema was NULL.
kInvalidSchemaInvalid schema.
kFileNotFoundThe file to be read could not be found.
kIoErrorReading the file failed.
kUriErrorAn invalid URI was found.
Description
Converts JSON Schema stored in memory. If this function is used, the JSON Schema is converted on the assumption that the URI of the JSON Schema is "nlibpath:///jsonschema/path/to/schema.json." Note this assumption if another JSON Schema is referenced from within the JSON Schema using "$ref".

◆ Export() [1/2]

nn::nlib::msgpack::JsonSchemaConverter::Export ( size_t *  written,
nlib_byte_t buf,
size_t  bufsize 
) const
noexcept

Writes JSON Schema converted to byte-code.

Parameters
[out]writtenThe number of bytes written.
[out]bufThe buffer that the data is written into.
[in]bufsizeThe size of the buffer.
Return values
0Success.
kInvalidParamwritten or buf is NULL.
kOutOfMemoryMemory allocation failed.
kBufferSizeNotEnoughInsufficient buffer size.
Description
Converts JSON Schema to byte-code in the msgpack format and writes it into the memory. Then, the written byte-code can be passed to JsonSchemaValidator::Init() for validation.

◆ Export() [2/2]

nn::nlib::msgpack::JsonSchemaConverter::Export ( ) const
noexcept

Returns JSON Schema converted into a byte-code.

Returns
A tupple of the error value, an area for the byte-code, and the byte-code size.
Description
Converts JSON Schema to byte-code in the msgpack format, writes it into the memory, and returns the buffer. Then, the written byte-code can be passed to JsonSchemaValidator::Init() for validation. As for the error value, if allocating memory fails, kOutOfMemory is set, or kInvalidSchema is set if the required memory size has exceeded 16 Mb.

◆ Init()

nn::nlib::msgpack::JsonSchemaConverter::Init ( const JsonSchemaConverterSettings settings)
noexcept

Initializes the object.

Parameters
[in]settingsStructure for specifying conversion options.
Return values
kOkSuccess.
kAlreadyInitializedThe object has been already initialized.
kOutOfMemoryMemory allocation failed.

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