Sync with 5.2.0
[deliverable/titan.core.git] / core / JSON.hh
1 ///////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2000-2014 Ericsson Telecom AB
3 // All rights reserved. This program and the accompanying materials
4 // are made available under the terms of the Eclipse Public License v1.0
5 // which accompanies this distribution, and is available at
6 // http://www.eclipse.org/legal/epl-v10.html
7 ///////////////////////////////////////////////////////////////////////////////
8 #ifndef JSON_HH_
9 #define JSON_HH_
10
11 #include "Types.h"
12
13 /** Descriptor for JSON encoding/decoding during runtime */
14 struct TTCN_JSONdescriptor_t
15 {
16 /** Encoding only.
17 * true : use the null literal to encode omitted fields in records or sets
18 * example: { field1 : value1, field2 : null, field3 : value3 }
19 * false : skip both the field name and the value if a field is omitted
20 * example: { field1 : value1, field3 : value3 }
21 * The decoder will always accept both variants. */
22 boolean omit_as_null;
23
24 /** An alias for the name of the field (in a record, set or union).
25 * Encoding: this alias will appear instead of the name of the field
26 * Decoding: the decoder will look for this alias instead of the field's real name*/
27 const char* alias;
28
29 /** If set, the union will be encoded as a JSON value instead of a JSON object
30 * with one name-value pair.
31 * Since the field name is no longer present, the decoder will determine the
32 * selected field based on the type of the value. The first field (in the order
33 * of declaration) that can successfully decode the value will be the selected one. */
34 boolean as_value;
35
36 /** Decoding only.
37 * Fields that don't appear in the JSON code will have this value assigned to
38 * them. */
39 const char* default_value;
40 };
41
42 /** This macro makes sure that error and warning messages will only be displayed
43 * if the silent flag is not set. */
44 #define JSON_ERROR if(!p_silent) TTCN_EncDec_ErrorContext::error
45
46 // JSON descriptors for base types
47 extern const TTCN_JSONdescriptor_t INTEGER_json_;
48 extern const TTCN_JSONdescriptor_t FLOAT_json_;
49 extern const TTCN_JSONdescriptor_t BOOLEAN_json_;
50 extern const TTCN_JSONdescriptor_t BITSTRING_json_;
51 extern const TTCN_JSONdescriptor_t HEXSTRING_json_;
52 extern const TTCN_JSONdescriptor_t OCTETSTRING_json_;
53 extern const TTCN_JSONdescriptor_t CHARSTRING_json_;
54 extern const TTCN_JSONdescriptor_t UNIVERSAL_CHARSTRING_json_;
55 extern const TTCN_JSONdescriptor_t VERDICTTYPE_json_;
56 extern const TTCN_JSONdescriptor_t GeneralString_json_;
57 extern const TTCN_JSONdescriptor_t NumericString_json_;
58 extern const TTCN_JSONdescriptor_t UTF8String_json_;
59 extern const TTCN_JSONdescriptor_t PrintableString_json_;
60 extern const TTCN_JSONdescriptor_t UniversalString_json_;
61 extern const TTCN_JSONdescriptor_t BMPString_json_;
62 extern const TTCN_JSONdescriptor_t GraphicString_json_;
63 extern const TTCN_JSONdescriptor_t IA5String_json_;
64 extern const TTCN_JSONdescriptor_t TeletexString_json_;
65 extern const TTCN_JSONdescriptor_t VideotexString_json_;
66 extern const TTCN_JSONdescriptor_t VisibleString_json_;
67 extern const TTCN_JSONdescriptor_t ASN_NULL_json_;
68 extern const TTCN_JSONdescriptor_t OBJID_json_;
69 extern const TTCN_JSONdescriptor_t ASN_ROID_json_;
70 extern const TTCN_JSONdescriptor_t ASN_ANY_json_;
71 extern const TTCN_JSONdescriptor_t ENUMERATED_json_;
72
73 /** JSON decoder error codes */
74 enum json_decode_error {
75 /** An unexpected JSON token was extracted. The token might still be valid and
76 * useful for the caller structured type. */
77 JSON_ERROR_INVALID_TOKEN = -1,
78 /** The JSON tokeniser couldn't extract a valid token (JSON_TOKEN_ERROR) or the
79 * format of the data extracted is invalid. In either case, this is a fatal
80 * error and the decoding cannot continue.
81 * @note This error code is always preceeded by a dynamic test case error, if the
82 * caller receives this code, it means that decoding error behavior is (at least
83 * partially) set to warnings. */
84 JSON_ERROR_FATAL = -2
85 };
86
87 // JSON decoding error messages
88 #define JSON_DEC_BAD_TOKEN_ERROR "Failed to extract valid token, invalid JSON format%s"
89 #define JSON_DEC_FORMAT_ERROR "Invalid JSON %s format, expecting %s value"
90 #define JSON_DEC_NAME_TOKEN_ERROR "Invalid JSON token, expecting JSON field name"
91 #define JSON_DEC_OBJECT_END_TOKEN_ERROR "Invalid JSON token, expecting JSON name-value pair or object end mark%s"
92 #define JSON_DEC_REC_OF_END_TOKEN_ERROR "Invalid JSON token, expecting JSON value or array end mark%s"
93 #define JSON_DEC_ARRAY_ELEM_TOKEN_ERROR "Invalid JSON token, expecting %d more JSON value%s"
94 #define JSON_DEC_ARRAY_END_TOKEN_ERROR "Invalid JSON token, expecting JSON array end mark%s"
95 #define JSON_DEC_FIELD_TOKEN_ERROR "Invalid JSON token found while decoding field '%s'"
96 #define JSON_DEC_INVALID_NAME_ERROR "Invalid field name '%s'"
97 #define JSON_DEC_MISSING_FIELD_ERROR "No JSON data found for field '%s'"
98 #define JSON_DEC_STATIC_OBJECT_END_TOKEN_ERROR "Invalid JSON token, expecting JSON object end mark%s"
99 #define JSON_DEC_AS_VALUE_ERROR "Extracted JSON %s could not be decoded by any field of the union"
100
101 #endif /* JSON_HH_ */
102
This page took 0.06559 seconds and 5 git commands to generate.