SequoiaDB
 All Classes Files Functions Variables Enumerations Enumerator
jstobs.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright (C) 2011-2018 SequoiaDB Ltd.
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 *******************************************************************************/
16 
20 #ifndef JSTOBS__H
21 #define JSTOBS__H
22 
23 #include "cJSON.h"
24 #include "core.h"
25 #include "bson/bson.h"
26 
27 #define JSON_DECIMAL_NO_CONVERT 0
28 #define JSON_DECIMAL_TO_DOUBLE 1
29 #define JSON_DECIMAL_TO_STRING 2
30 
31 /* Flags */
32 //Check the characters behind json
33 #define JSON_FLAG_CHECK_END 0x00000001
34 
35 //Escape Unicode encoding
36 #define JSON_FLAG_ESCAPE_UNICODE 0x00000002
37 
38 //Append the _id field
39 #define JSON_FLAG_APPEND_OID 0x00000004
40 
41 //Do not initialize bson
42 #define JSON_FLAG_NOT_INIT_BSON 0x00000008
43 
44 //Strictly parse json format
45 #define JSON_FLAG_RIGOROUS_MODE 0x00000010
46 
47 //Decimal forced conversion to double
48 #define JSON_FLAG_DECIMAL_TO_DOUBLE 0x00000020
49 
50 //Decimal forced conversion to string
51 #define JSON_FLAG_DECIMAL_TO_STRING 0x00000040
52 
53 SDB_EXTERN_C_START
54 
62 SDB_EXPORT void JsonSetPrintfLog( void (*pFun)( const CHAR *pFunc,
63  const CHAR *pFile,
64  UINT32 line,
65  const CHAR *pFmt,
66  ... ) ) ;
67 
68 //Compatible with the old version, the new code is not recommended use.
69 SDB_EXPORT BOOLEAN jsonToBson ( bson *bs, const CHAR *json_str ) ;
70 
71 //Compatible with the old version, the new code is not recommended use.
72 SDB_EXPORT BOOLEAN jsonToBson2 ( bson *bs,
73  const CHAR *json_str,
74  BOOLEAN isMongo,
75  BOOLEAN isBatch ) ;
76 
84 SDB_EXPORT BOOLEAN json2bson2( const CHAR *pJson, bson *pBson ) ;
85 
106 SDB_EXPORT BOOLEAN json2bson( const CHAR *pJson,
107  CJSON_MACHINE *pMachine,
108  INT32 parseMode,
109  BOOLEAN isCheckEnd,
110  BOOLEAN isUnicode,
111  INT32 decimalto,
112  bson *pBson ) ;
113 
133 SDB_EXPORT BOOLEAN json2bson3( const CHAR *pJson, CJSON_MACHINE *pMachine,
134  INT32 flags, bson *pBson ) ;
135 
136 SDB_EXPORT void setJsonPrecision( const CHAR *pFloatFmt ) ;
137 
152 SDB_EXPORT BOOLEAN bsonToJson ( CHAR *buffer, INT32 bufsize, const bson *b,
153  BOOLEAN toCSV, BOOLEAN skipUndefined ) ;
154 
169 SDB_EXPORT BOOLEAN bsonToJson2 ( CHAR *buffer, INT32 bufsize, const bson *b,
170  BOOLEAN isStrict ) ;
171 
172 SDB_EXTERN_C_END
173 
174 #endif // end JSTOBS__H