Skip to content

Commit

Permalink
fix rapidJSON assertion failed
Browse files Browse the repository at this point in the history
  • Loading branch information
cyshi committed Feb 10, 2022
1 parent fb1a1cb commit 405745b
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions src/sofa/pbrpc/pbjson.cc
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ static int json2field(const rapidjson::Value* json, Message* msg, const FieldDes
{
case FieldDescriptor::CPPTYPE_INT32:
{
if (json->GetType() != rapidjson::kNumberType)
if (!json->IsInt())
{
RETURN_ERR(ERR_INVALID_JSON, "Not a number");
RETURN_ERR(ERR_INVALID_JSON, "Not an int32 number");
}
if (repeated)
{
Expand All @@ -299,9 +299,9 @@ static int json2field(const rapidjson::Value* json, Message* msg, const FieldDes
}
case FieldDescriptor::CPPTYPE_UINT32:
{
if (json->GetType() != rapidjson::kNumberType)
if (!json->IsUint())
{
RETURN_ERR(ERR_INVALID_JSON, "Not a number");
RETURN_ERR(ERR_INVALID_JSON, "Not an uint32 number");
}
if (repeated)
{
Expand All @@ -315,9 +315,9 @@ static int json2field(const rapidjson::Value* json, Message* msg, const FieldDes
}
case FieldDescriptor::CPPTYPE_INT64:
{
if (json->GetType() != rapidjson::kNumberType)
if (!json->IsInt64())
{
RETURN_ERR(ERR_INVALID_JSON, "Not a number");
RETURN_ERR(ERR_INVALID_JSON, "Not an int64 number");
}
if (repeated)
{
Expand All @@ -331,9 +331,9 @@ static int json2field(const rapidjson::Value* json, Message* msg, const FieldDes
}
case FieldDescriptor::CPPTYPE_UINT64:
{
if (json->GetType() != rapidjson::kNumberType)
if (!json->IsUint64())
{
RETURN_ERR(ERR_INVALID_JSON, "Not a number");
RETURN_ERR(ERR_INVALID_JSON, "Not an uint64 number");
}
if (repeated)
{
Expand All @@ -347,9 +347,9 @@ static int json2field(const rapidjson::Value* json, Message* msg, const FieldDes
}
case FieldDescriptor::CPPTYPE_DOUBLE:
{
if (json->GetType() != rapidjson::kNumberType)
if (!json->IsDouble())
{
RETURN_ERR(ERR_INVALID_JSON, "Not a number");
RETURN_ERR(ERR_INVALID_JSON, "Not a float number");
}
if (repeated)
{
Expand All @@ -363,9 +363,9 @@ static int json2field(const rapidjson::Value* json, Message* msg, const FieldDes
}
case FieldDescriptor::CPPTYPE_FLOAT:
{
if (json->GetType() != rapidjson::kNumberType)
if (!json->IsDouble())
{
RETURN_ERR(ERR_INVALID_JSON, "Not a number");
RETURN_ERR(ERR_INVALID_JSON, "Not a float number");
}
if (repeated)
{
Expand All @@ -379,7 +379,7 @@ static int json2field(const rapidjson::Value* json, Message* msg, const FieldDes
}
case FieldDescriptor::CPPTYPE_BOOL:
{
if (json->GetType() != rapidjson::kTrueType && json->GetType() != rapidjson::kFalseType)
if (!json->IsBool())
{
RETURN_ERR(ERR_INVALID_JSON, "Not a bool");
}
Expand All @@ -396,7 +396,7 @@ static int json2field(const rapidjson::Value* json, Message* msg, const FieldDes
}
case FieldDescriptor::CPPTYPE_STRING:
{
if (json->GetType() != rapidjson::kStringType)
if (!json->IsString())
{
RETURN_ERR(ERR_INVALID_JSON, "Not a string");
}
Expand Down Expand Up @@ -436,11 +436,23 @@ static int json2field(const rapidjson::Value* json, Message* msg, const FieldDes
{
const EnumDescriptor *ed = field->enum_type();
const EnumValueDescriptor *ev = 0;
if (json->GetType() == rapidjson::kNumberType)
if (json->IsInt())
{
ev = ed->FindValueByNumber(json->GetInt());
}
else if (json->GetType() == rapidjson::kStringType)
else if (json->IsUint())
{
ev = ed->FindValueByNumber(json->GetUint());
}
else if (json->IsInt64())
{
ev = ed->FindValueByNumber(json->GetInt64());
}
else if (json->IsUint64())
{
ev = ed->FindValueByNumber(json->GetUint64());
}
else if (json->IsString())
{
ev = ed->FindValueByName(json->GetString());
}
Expand Down

0 comments on commit 405745b

Please sign in to comment.