static bool ParseFromStr()

in pb.cpp [129:197]


static bool ParseFromStr(const SlsStringPiece& str, SLS_OUT LogGroup& result)
{
    const char* pos = str.mPtr;
    const char* end = str.mPtr + str.mLen;
    while (pos < end)
    {
        uint32_t head = 0;
        pos = GetVarint32Ptr(pos, end, &head);
        IF_CONFITION_RETURN_FALSE(pos == nullptr);
        uint32_t mode = head & 0x7;
        uint32_t index = head >> 3;

        if (index != 1 && index != 3 && index != 4 && index != 6)
        {
            pos = SkipProtobufField(pos, end, mode);
            IF_CONFITION_RETURN_FALSE(pos == nullptr);
            continue;
        }

        CHECK_FIELD_TYPE(index, mode, 2);
        uint32_t len = 0;
        pos = GetVarint32Ptr(pos, end, &len);
        IF_CONFITION_RETURN_FALSE(pos == nullptr || pos + len > end);

        switch (index)
        {
        case 1: // logs
        {
            Log log;
            if (!ParseFromStr(SlsStringPiece(pos, len), log))
                return false;
            result.logs.push_back(std::move(log));
            pos += len;
            break;
        }

        case 3: // topic
        {
            result.topic = std::string(pos, len);
            pos += len;
            break;
        }

        case 4: // source
        {
            result.source = std::string(pos, len);
            pos += len;
            break;
        }

        case 6: // tags
        {
            KvPair pair;
            if (!ParseFromStr(SlsStringPiece(pos, len), pair))
                return false;
            result.logTags.emplace_back(pair.first, pair.second);
            pos += len;
            break;
        }

        default:
        {
            // unreachable
            break;
        }
        }
    }
    return pos == end;
}