MCPcopy Create free account
hub / github.com/apache/brpc / JsonToProtoMessageInline

Function JsonToProtoMessageInline

src/json2pb/json_to_pb.cpp:631–660  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

629}
630
631inline bool JsonToProtoMessageInline(const std::string& json_string,
632 google::protobuf::Message* message,
633 const Json2PbOptions& options,
634 std::string* error,
635 size_t* parsed_offset) {
636 if (error) {
637 error->clear();
638 }
639 BUTIL_RAPIDJSON_NAMESPACE::Document d;
640 if (options.allow_remaining_bytes_after_parsing) {
641 d.Parse<RAPIDJSON_PARSE_FLAG_STOP_WHEN_DONE>(json_string.c_str());
642 if (parsed_offset != nullptr) {
643 *parsed_offset = d.GetErrorOffset();
644 }
645 } else {
646 d.Parse<RAPIDJSON_PARSE_FLAG_DEFAULT>(json_string.c_str());
647 }
648 if (d.HasParseError()) {
649 if (options.allow_remaining_bytes_after_parsing) {
650 if (d.GetParseError() == BUTIL_RAPIDJSON_NAMESPACE::kParseErrorDocumentEmpty) {
651 // This is usual when parsing multiple jsons, don't waste time
652 // on setting the `empty error'
653 return false;
654 }
655 }
656 J2PERROR_WITH_PB(message, error, "Invalid json: %s", BUTIL_RAPIDJSON_NAMESPACE::GetParseError_En(d.GetParseError()));
657 return false;
658 }
659 return JsonValueToProtoMessage(d, message, options, error, 0);
660}
661
662bool JsonToProtoMessage(const std::string& json_string,
663 google::protobuf::Message* message,

Callers 1

JsonToProtoMessageFunction · 0.85

Calls 3

JsonValueToProtoMessageFunction · 0.85
clearMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected