Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fa4df74e
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
fa4df74e
编写于
12月 30, 2022
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix:json parse error
上级
e6627f69
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
39 addition
and
19 deletion
+39
-19
source/client/inc/clientSml.h
source/client/inc/clientSml.h
+2
-2
source/client/src/clientSmlJson.c
source/client/src/clientSmlJson.c
+37
-17
未找到文件。
source/client/inc/clientSml.h
浏览文件 @
fa4df74e
...
...
@@ -206,8 +206,8 @@ typedef int32_t (*_equal_fn_sml)(const void *, const void *);
SSmlHandle
*
smlBuildSmlInfo
(
TAOS
*
taos
);
void
smlDestroyInfo
(
SSmlHandle
*
info
);
void
smlJsonParseObjFirst
(
char
**
start
,
SSmlLineInfo
*
element
,
int8_t
*
offset
);
void
smlJsonParseObj
(
char
**
start
,
SSmlLineInfo
*
element
,
int8_t
*
offset
);
int
smlJsonParseObjFirst
(
char
**
start
,
SSmlLineInfo
*
element
,
int8_t
*
offset
);
int
smlJsonParseObj
(
char
**
start
,
SSmlLineInfo
*
element
,
int8_t
*
offset
);
SArray
*
smlJsonParseTags
(
char
*
start
,
char
*
end
);
bool
smlParseNumberOld
(
SSmlKv
*
kvVal
,
SSmlMsgBuf
*
msg
);
void
*
nodeListGet
(
NodeList
*
list
,
const
void
*
key
,
int32_t
len
,
_equal_fn_sml
fn
);
...
...
source/client/src/clientSmlJson.c
浏览文件 @
fa4df74e
...
...
@@ -117,6 +117,11 @@ static int32_t smlParseTagsFromJSON(SSmlHandle *info, SSmlLineInfo *elements) {
SArray
*
tags
=
smlJsonParseTags
(
elements
->
tags
,
elements
->
tags
+
elements
->
tagsLen
);
int32_t
tagNum
=
taosArrayGetSize
(
tags
);
if
(
tagNum
==
0
)
{
uError
(
"SML:tag is empty:%s"
,
elements
->
tags
)
taosArrayDestroy
(
tags
);
return
TSDB_CODE_SML_INVALID_DATA
;
}
for
(
int32_t
i
=
0
;
i
<
tagNum
;
++
i
)
{
SSmlKv
kv
=
*
(
SSmlKv
*
)
taosArrayGet
(
tags
,
i
);
...
...
@@ -236,7 +241,7 @@ static char* smlJsonGetObj(char *payload){
return
NULL
;
}
void
smlJsonParseObjFirst
(
char
**
start
,
SSmlLineInfo
*
element
,
int8_t
*
offset
){
int
smlJsonParseObjFirst
(
char
**
start
,
SSmlLineInfo
*
element
,
int8_t
*
offset
){
int
index
=
0
;
while
(
*
(
*
start
)){
if
((
*
start
)[
0
]
!=
'"'
){
...
...
@@ -244,10 +249,6 @@ void smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset){
continue
;
}
if
(
unlikely
(
index
>=
4
))
{
uError
(
"index >= 4, %s"
,
*
start
)
break
;
}
char
*
sTmp
=
*
start
;
if
((
*
start
)[
1
]
==
'm'
&&
(
*
start
)[
2
]
==
'e'
&&
(
*
start
)[
3
]
==
't'
&&
(
*
start
)[
4
]
==
'r'
&&
(
*
start
)[
5
]
==
'i'
&&
(
*
start
)[
6
]
==
'c'
&&
(
*
start
)[
7
]
==
'"'
){
...
...
@@ -336,9 +337,15 @@ void smlJsonParseObjFirst(char **start, SSmlLineInfo *element, int8_t *offset){
}
(
*
start
)
++
;
}
if
(
unlikely
(
index
!=
OTD_JSON_FIELDS_NUM
))
{
uError
(
"elements != %d"
,
OTD_JSON_FIELDS_NUM
)
return
-
1
;
}
return
0
;
}
void
smlJsonParseObj
(
char
**
start
,
SSmlLineInfo
*
element
,
int8_t
*
offset
){
int
smlJsonParseObj
(
char
**
start
,
SSmlLineInfo
*
element
,
int8_t
*
offset
){
int
index
=
0
;
while
(
*
(
*
start
)){
if
((
*
start
)[
0
]
!=
'"'
){
...
...
@@ -346,10 +353,6 @@ void smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset){
continue
;
}
if
(
unlikely
(
index
>=
4
))
{
uError
(
"index >= 4, %s"
,
*
start
)
break
;
}
if
((
*
start
)[
1
]
==
'm'
){
(
*
start
)
+=
offset
[
index
++
];
element
->
measure
=
*
start
;
...
...
@@ -396,23 +399,36 @@ void smlJsonParseObj(char **start, SSmlLineInfo *element, int8_t *offset){
}
(
*
start
)
++
;
}
if
(
unlikely
(
index
!=
OTD_JSON_FIELDS_NUM
))
{
uError
(
"elements != %d"
,
OTD_JSON_FIELDS_NUM
)
return
-
1
;
}
return
0
;
}
static
int32_t
smlParseJSONString
(
SSmlHandle
*
info
,
char
**
start
,
SSmlLineInfo
*
elements
)
{
int32_t
ret
=
TSDB_CODE_SUCCESS
;
if
(
info
->
offset
[
0
]
==
0
){
smlJsonParseObjFirst
(
start
,
elements
,
info
->
offset
);
ret
=
smlJsonParseObjFirst
(
start
,
elements
,
info
->
offset
);
}
else
{
smlJsonParseObj
(
start
,
elements
,
info
->
offset
);
ret
=
smlJsonParseObj
(
start
,
elements
,
info
->
offset
);
}
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
if
(
**
start
==
'\0'
&&
elements
->
measure
==
NULL
)
return
TSDB_CODE_SUCCESS
;
if
(
unlikely
(
**
start
==
'\0'
&&
elements
->
measure
==
NULL
))
return
TSDB_CODE_SUCCESS
;
SSmlKv
kv
=
{.
key
=
VALUE
,
.
keyLen
=
VALUE_LEN
,
.
value
=
elements
->
cols
,
.
length
=
(
size_t
)
elements
->
colsLen
};
if
(
smlParseValue
(
&
kv
,
&
info
->
msgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
elements
->
colsLen
==
0
||
smlParseValue
(
&
kv
,
&
info
->
msgBuf
)
!=
TSDB_CODE_SUCCESS
)
{
uError
(
"SML:cols invalidate:%s"
,
elements
->
cols
);
return
TSDB_CODE_TSC_INVALID_VALUE
;
}
// Parse tags
ret
=
smlParseTagsFromJSON
(
info
,
elements
);
if
(
unlikely
(
ret
))
{
...
...
@@ -725,6 +741,10 @@ static int32_t smlParseTagsFromJSONExt(SSmlHandle *info, cJSON *tags, SSmlLineIn
}
int32_t
tagNum
=
cJSON_GetArraySize
(
tags
);
if
(
unlikely
(
tagNum
==
0
)){
uError
(
"SML:Tag should not be empty"
);
return
TSDB_CODE_TSC_INVALID_JSON
;
}
for
(
int32_t
i
=
0
;
i
<
tagNum
;
++
i
)
{
cJSON
*
tag
=
cJSON_GetArrayItem
(
tags
,
i
);
if
(
unlikely
(
tag
==
NULL
))
{
...
...
@@ -1046,7 +1066,7 @@ static int32_t smlParseJSONExt(SSmlHandle *info, char *payload) {
}
else
if
(
cJSON_IsObject
(
info
->
root
))
{
payloadNum
=
1
;
}
else
{
uError
(
"SML:0x%"
PRIx64
" Invalid JSON Payload
"
,
info
->
i
d
);
uError
(
"SML:0x%"
PRIx64
" Invalid JSON Payload
3:%s"
,
info
->
id
,
payloa
d
);
return
TSDB_CODE_TSC_INVALID_JSON
;
}
...
...
@@ -1072,7 +1092,7 @@ static int32_t smlParseJSONExt(SSmlHandle *info, char *payload) {
ret
=
smlParseJSONStringExt
(
info
,
dataPoint
,
info
->
lines
+
cnt
);
}
if
(
unlikely
(
ret
!=
TSDB_CODE_SUCCESS
))
{
uError
(
"SML:0x%"
PRIx64
" Invalid JSON Payload
"
,
info
->
i
d
);
uError
(
"SML:0x%"
PRIx64
" Invalid JSON Payload
2:%s"
,
info
->
id
,
payloa
d
);
return
ret
;
}
...
...
@@ -1115,7 +1135,7 @@ int32_t smlParseJSON(SSmlHandle *info, char *payload) {
ret
=
smlParseJSONString
(
info
,
&
dataPointStart
,
info
->
lines
+
cnt
);
}
if
(
unlikely
(
ret
!=
TSDB_CODE_SUCCESS
))
{
uError
(
"SML:0x%"
PRIx64
" Invalid JSON Payload
"
,
info
->
i
d
);
uError
(
"SML:0x%"
PRIx64
" Invalid JSON Payload
1:%s"
,
info
->
id
,
payloa
d
);
return
smlParseJSONExt
(
info
,
payload
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录