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

constexpr JsonSchemaConverter () noexcept
 Instantiates the object with default parameters (default constructor).
 
 ~JsonSchemaConverter () noexcept
 Destructor.
 
Result Init (const JsonSchemaConverterSettings &settings) noexcept
 Initializes the object. More...
 
Result Init () noexcept
 Initializes JsonSchemaConverterSettings with the default values.
 
void Reset () noexcept
 Sets the object to the same state as the one obtained after the default constructor has run.
 
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
 Writes JSON Schema converted to byte-code. More...
 

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.

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]

template<size_t N>
nn::nlib::msgpack::JsonSchemaConverter::Export ( size_t *  written,
nlib_byte_t(&)  buf[N] 
) const
inlinenoexcept

Writes JSON Schema converted to byte-code.

Template Parameters
NThe size of the buffer.
Parameters
[out]writtenThe number of bytes written.
[out]bufThe buffer that the data is written into.
Return values
0Success.
kOutOfMemoryMemory allocation failed.
kBufferSizeNotEnoughInsufficient buffer size.

Definition at line 99 of file JsonSchema.h.

◆ 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: