nlib
JsonSchema.h
[詳解]
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
デストラクタです。
Definition: JsonSchema.h:47
Result Export(size_t *written, nlib_byte_t(&buf)[N]) const noexcept
バイトコードに変換したJSON Schemaを書き込みます。
Definition: JsonSchema.h:99
#define NLIB_DISALLOW_COPY_AND_ASSIGN(TypeName)
TypeName で指定されたクラスのコピーコンストラクタと代入演算子を禁止します。
Definition: Config.h:179
Result
関数の実行結果です。
Definition: JsonSchema.h:34
ファイルの読み込み中に失敗しました。
Definition: JsonSchema.h:79
JsonStreamParserSettings parser_settings
JSON Schemaをパースするための設定です。
Definition: JsonSchema.h:66
bool encode_description
現在のところこの変数は無視されます。
Definition: JsonSchema.h:64
constexpr JsonSchemaConverter() noexcept
デフォルトコンストラクタです。
Definition: JsonSchema.h:86
JsonSchemaConverterの動作オプションを指定します。
Definition: JsonSchema.h:58
Result
関数の実行結果です。
Definition: JsonSchema.h:72
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
MessagePack又はJSONを読み込むことで作成されるオブジェクトです。
Definition: MpObject.h:95
URIの処理でエラーが発生しました。
Definition: JsonSchema.h:80
bool encode_title
現在のところこの変数は無視されます。
Definition: JsonSchema.h:63
~JsonSchemaConverter() noexcept
デストラクタです。
Definition: JsonSchema.h:87
JsonStreamParserの設定パラメータ群を格納する構造体です。
MessagePack, JSON及びCSVを読み込むと作成されるオブジェクトです。
メモリの確保に失敗しました。
Definition: JsonSchema.h:76
JSON Schemaの検証に失敗した場合、pathというメンバに検証に失敗した場所についての文字列が書き込まれます...
Definition: JsonSchema.h:43
機種依存しないURIによるパス記述からネイティブのパス文字列を得るためのクラスです。 ...
JSON Schemaによる検証に失敗しました。
Definition: JsonSchema.h:39
JSON SchemaをJsonSchemaValidatorで利用できるバイトコード形式に変換します。
Definition: JsonSchema.h:70
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
Result Init() noexcept
JsonSchemaConverterSettingsをデフォルトにして初期化します。
Definition: JsonSchema.h:90
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
指定されたファイルが見つかりませんでした。
Definition: JsonSchema.h:78
メモリの確保に失敗しました。
Definition: JsonSchema.h:38
const NativePathMapper * uri_mapper
URIをファイルパスに変換するためのオブジェクトへのポインタを設定します。NULLを指定することが可能です。...
Definition: JsonSchema.h:65
URIによるパス記述からプラットフォーム固有のパス記述を得るためのクラスが定義されています。 ...
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
JSON Schemaの変換に失敗した場合、pathというメンバに変換に失敗した場所についての文字列が書き込まれます...
Definition: JsonSchema.h:83
unsigned char nlib_byte_t
C++17以降でstd::byteにtypedefされる型です。
Definition: Platform.h:319
char nlib_utf8_t
charのtypedefです。文字列がUTF-8であることを示します。
Definition: Platform.h:308
JSON SchemaによりJSONやmsgpackの検証を行うためのクラスです。
Definition: JsonSchema.h:32
constexpr JsonSchemaValidator() noexcept
デフォルトコンストラクタです。
Definition: JsonSchema.h:46