static bool ParseFromStr()

in pb.cpp [68:127]


static bool ParseFromStr(const SlsStringPiece& str, SLS_OUT Log& result)
{
    const char* pos = str.mPtr;
    const char* end = str.mPtr + str.mLen;
    bool hasTime = false;
    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;
        switch (index)
        {
        case 1: // log time
        {
            CHECK_FIELD_TYPE(index, mode, 0);
            IF_CONFITION_RETURN_FALSE(hasTime);
            uint32_t data_time;
            pos = GetVarint32Ptr(pos, end, &data_time);
            IF_CONFITION_RETURN_FALSE(pos == nullptr);
            result.time = data_time;
            hasTime = true;
            break;
        }

        case 2: // log content
        {
            CHECK_FIELD_TYPE(index, mode, 2);
            uint32_t len = 0;
            pos = GetVarint32Ptr(pos, end, &len);
            IF_CONFITION_RETURN_FALSE(pos == nullptr || pos + len > end);
            KvPair pair;
            if (!ParseFromStr(SlsStringPiece(pos, len), pair))
                return false;
            result.contents.emplace_back(pair.first, pair.second);
            pos += len;
            break;
        }

        case 4: // nano time
        {
            CHECK_FIELD_TYPE(index, mode, 5);
            IF_CONFITION_RETURN_FALSE(pos + 4 > end);
            std::memcpy(&result.timeNs, pos, 4);
            result.hasTimeNs = true;
            pos += 4;
            break;
        }

        default:
        {
            pos = SkipProtobufField(pos, end, mode);
            IF_CONFITION_RETURN_FALSE(pos == nullptr);
            break;
        }
        }
    }
    return hasTime && (pos == end);
}