Exemple #1
0
bool IDBKeyPath::decode(KeyedDecoder& decoder, IDBKeyPath& result)
{
    auto enumFunction = [](int64_t value) {
        return value == NullType || value == StringType || value == ArrayType;
    };

    if (!decoder.decodeVerifiedEnum("type", result.m_type, enumFunction))
        return false;

    if (result.m_type == NullType)
        return true;

    if (result.m_type == StringType)
        return decoder.decodeString("string", result.m_string);

    ASSERT(result.m_type == ArrayType);

    auto arrayFunction = [](KeyedDecoder& decoder, String& result) {
        return decoder.decodeString("string", result);
    };

    return decoder.decodeObjects("array", result.m_array, arrayFunction);
}
bool IDBKeyData::decode(KeyedDecoder& decoder, IDBKeyData& result)
{
    if (!decoder.decodeBool("null", result.m_isNull))
        return false;

    if (result.m_isNull)
        return true;

    auto enumFunction = [](int64_t value) {
        return value == KeyType::Max
            || value == KeyType::Invalid
            || value == KeyType::Array
            || value == KeyType::String
            || value == KeyType::Date
            || value == KeyType::Number
            || value == KeyType::Min;
    };
    if (!decoder.decodeEnum("m_type", result.m_type, enumFunction))
        return false;

    if (result.m_type == KeyType::Invalid)
        return true;

    if (result.m_type == KeyType::Max)
        return true;

    if (result.m_type == KeyType::Min)
        return true;

    if (result.m_type == KeyType::String)
        return decoder.decodeString("string", result.m_stringValue);

    if (result.m_type == KeyType::Number || result.m_type == KeyType::Date)
        return decoder.decodeDouble("number", result.m_numberValue);

    ASSERT(result.m_type == KeyType::Array);

    auto arrayFunction = [](KeyedDecoder& decoder, IDBKeyData& result) {
        return decode(decoder, result);
    };
    
    result.m_arrayValue.clear();
    return decoder.decodeObjects("array", result.m_arrayValue, arrayFunction);
}
Exemple #3
0
static bool decodeElement(KeyedDecoder& decoder, FormDataElement& element)
{
    if (!decoder.decodeEnum("type", element.m_type, [](FormDataElement::Type type) {
        switch (type) {
        case FormDataElement::Type::Data:
        case FormDataElement::Type::EncodedFile:
        case FormDataElement::Type::EncodedBlob:
            return true;
        }

        return false;
    }))
        return false;

    switch (element.m_type) {
    case FormDataElement::Type::Data:
        if (!decoder.decodeBytes("data", element.m_data))
            return false;
        break;

    case FormDataElement::Type::EncodedFile: {
        if (!decoder.decodeString("filename", element.m_filename))
            return false;
        if (!decoder.decodeString("generatedFilename", element.m_generatedFilename))
            return false;
        if (!decoder.decodeBool("shouldGenerateFile", element.m_shouldGenerateFile))
            return false;

        int64_t fileStart;
        if (!decoder.decodeInt64("fileStart", fileStart))
            return false;
        if (fileStart < 0)
            return false;

        int64_t fileLength;
        if (!decoder.decodeInt64("fileLength", fileLength))
            return false;
        if (fileLength != BlobDataItem::toEndOfFile && fileLength < fileStart)
            return false;

        double expectedFileModificationTime;
        if (!decoder.decodeDouble("expectedFileModificationTime", expectedFileModificationTime))
            return false;

        element.m_fileStart = fileStart;
        element.m_fileLength = fileLength;
        element.m_expectedFileModificationTime = expectedFileModificationTime;
        break;
    }

    case FormDataElement::Type::EncodedBlob: {
        String blobURLString;
        if (!decoder.decodeString("url", blobURLString))
            return false;

        element.m_url = URL(URL(), blobURLString);
        break;
    }
    }

    return true;
}