nlib
JsonSchema.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
13  *--------------------------------------------------------------------------------*/
14 #pragma once
15 #ifndef INCLUDE_NN_NLIB_MSGPACK_JSONSCHEMA_H_
16 #define INCLUDE_NN_NLIB_MSGPACK_JSONSCHEMA_H_
17 
18 #include <utility>
22 #include "nn/nlib/Swap.h"
23 
24 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
25 #undef NLIB_VIS_PUBLIC
26 #define NLIB_VIS_PUBLIC NLIB_WINEXPORT
27 #endif
28 NLIB_NAMESPACE_BEGIN
29 namespace msgpack {
30 
31 class JsonSchemaValidatorPrivate;
33  public:
34  enum Result {
35  kOk = 0,
41  kVersionNotSupported
42  };
43  struct Detail {
44  nlib_utf8_t path[1024];
45  };
48  NLIB_DEFMOVE_PIMPL(JsonSchemaValidator);
49  void Reset() NLIB_NOEXCEPT;
50  Result Init(const nlib_byte_t* schema_bytecode, size_t n) NLIB_NOEXCEPT;
51  Result Validate(const MpObject& obj, Detail* detail) NLIB_NOEXCEPT;
52 
53  private:
54  JsonSchemaValidatorPrivate* prv_;
56 };
57 
60  encode_description(false),
61  uri_mapper(nullptr),
62  parser_settings() {}
67 };
68 
69 class JsonSchemaConverterPrivate;
71  public:
72  enum Result {
73  kOk = 0,
81  kBufferSizeNotEnough
82  };
83  struct Detail {
84  nlib_utf8_t path[1024];
85  };
88  NLIB_DEFMOVE_PIMPL(JsonSchemaConverter);
89  Result Init(const JsonSchemaConverterSettings& settings) NLIB_NOEXCEPT;
92  return Init(settings);
93  }
94  void Reset() NLIB_NOEXCEPT;
95  Result Convert(const char* uri, Detail* detail) NLIB_NOEXCEPT;
96  Result Convert(MpObject* schema, Detail* detail) NLIB_NOEXCEPT;
97  Result Export(size_t* written, nlib_byte_t* buf, size_t bufsize) const NLIB_NOEXCEPT;
98  template<size_t N>
99  Result Export(size_t* written, nlib_byte_t (&buf)[N]) const NLIB_NOEXCEPT {
100  return Export(written, &buf[0], N);
101  }
102 #ifdef __cpp_rvalue_references
103  std::tuple<Result, std::unique_ptr<nlib_byte_t[]>, size_t> Export() const NLIB_NOEXCEPT;
104 #endif
105 
106  private:
107  JsonSchemaConverterPrivate* prv_;
109 };
110 
111 } // namespace msgpack
112 NLIB_NAMESPACE_END
113 
114 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::JsonSchemaConverter)
115 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::JsonSchemaValidator)
116 
117 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
118 #undef NLIB_VIS_PUBLIC
119 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
120 #endif
121 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONSCHEMA_H_
~JsonSchemaValidator() noexcept
Destructor.
Definition: JsonSchema.h:47
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
Prohibits use of the copy constructor and assignment operator for the class specified by TypeName...
Definition: Config.h:183
Result
The result of the function executed.
Definition: JsonSchema.h:34
Failed while reading the file.
Definition: JsonSchema.h:79
JsonStreamParserSettings parser_settings
This setting is provided to parse JSON Schema.
Definition: JsonSchema.h:66
bool encode_description
As of now, this variable is ignored.
Definition: JsonSchema.h:64
constexpr JsonSchemaConverter() noexcept
Instantiates the object with default parameters (default constructor).
Definition: JsonSchema.h:86
Specifies options for operating JsonSchemaConverter.
Definition: JsonSchema.h:58
Result
The result of the function executed.
Definition: JsonSchema.h:72
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:87
Object created when MessagePack or JSON is read.
Definition: MpObject.h:96
An error occurred in processing the URI.
Definition: JsonSchema.h:80
bool encode_title
As of now, this variable is ignored.
Definition: JsonSchema.h:63
~JsonSchemaConverter() noexcept
Destructor.
Definition: JsonSchema.h:87
Data structure used to store the JsonStreamParser settings parameters.
Object created when MessagePack, JSON, or CSV is read.
The classes for parsing JSON or MessagePack have been defined.
If the validation with JSON Schema has failed, a string representing the location where the validatio...
Definition: JsonSchema.h:43
The class for getting the native path string from the URI path notation that is not machine-dependent...
The validation with JSON Schema has failed.
Definition: JsonSchema.h:39
Converts JSON Schema to a byte-code format available for JsonSchemaValidator.
Definition: JsonSchema.h:70
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:109
Result Init() noexcept
A parameter omitted version of the above function which passes settings as the default value...
Definition: JsonSchema.h:90
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:111
The specified file could not be found.
Definition: JsonSchema.h:78
const NativePathMapper * uri_mapper
Sets the pointer to an object that is to be used to convert a URI to a file path. You can specify NUL...
Definition: JsonSchema.h:65
Defines the class for getting the platform-specific path notation from the URI path notation...
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:250
If the conversion of JSON Schema has failed, a string representing the location where the conversion ...
Definition: JsonSchema.h:83
unsigned char nlib_byte_t
This type will be defined as std::byte in a typedef of C++17 or later.
Definition: Platform.h:314
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:303
These classes are used to validate JSON and msgpack using JSON Schema.
Definition: JsonSchema.h:32
constexpr JsonSchemaValidator() noexcept
Instantiates the object with default parameters (default constructor).
Definition: JsonSchema.h:46