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>
21 #include "nn/nlib/msgpack/JsonStreamParser.h"
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,
36  kInvalidParam,
37  kAlreadyInitialized,
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_title(false), encode_description(false),
61  uri_mapper(nullptr), parser_settings() {
62  }
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;
90  Result Init() 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::pair<Result, size_t>
104  Export(nlib_byte_t* buf, size_t bufsize) const NLIB_NOEXCEPT {
105  std::pair<Result, size_t> rval;
106  rval.first = Export(&rval.second, buf, bufsize);
107  return rval;
108  }
109  template<size_t N>
110  std::pair<Result, size_t>
111  Export(nlib_byte_t (&buf)[N]) const NLIB_NOEXCEPT {
112  return Export(&buf[0], N);
113  }
114 #endif
115 
116  private:
117  JsonSchemaConverterPrivate* prv_;
119 };
120 
121 } // namespace msgpack
122 NLIB_NAMESPACE_END
123 
124 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::JsonSchemaConverter)
125 NLIB_DEFINE_STD_SWAP(::nlib_ns::msgpack::JsonSchemaValidator)
126 
127 #if defined(_MSC_VER) && defined(nx_msgpack_EXPORTS)
128 #undef NLIB_VIS_PUBLIC
129 #define NLIB_VIS_PUBLIC NLIB_WINIMPORT
130 #endif
131 #endif // INCLUDE_NN_NLIB_MSGPACK_JSONSCHEMA_H_
~JsonSchemaValidator() noexcept
Destructor.
Definition: JsonSchema.h:47
Result Export(size_t *written, nlib_byte_t(&buf)[N]) const noexcept
Writes JSON Schema converted to byte-code.
Definition: JsonSchema.h:99
#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:179
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:89
Object created when MessagePack or JSON is read.
Definition: MpObject.h:95
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.
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:105
Result Init() noexcept
Initializes JsonSchemaConverterSettings with the default values.
Definition: JsonSchema.h:90
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:107
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:245
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:319
char nlib_utf8_t
Defines char with a typedef. Indicates that it is a UTF-8 string.
Definition: Platform.h:308
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