bool encodeCondition(conditionType condition) { return( encodeByte(CONDITION_CODE_TAG) && encodeByte(condition) ); }
Vector<char> ObjectStoreMetaDataKey::encode(int64_t databaseId, int64_t objectStoreId, unsigned char metaDataType) { KeyPrefix prefix(databaseId, 0, 0); Vector<char> ret = prefix.encode(); ret.append(encodeByte(ObjectStoreMetaDataTypeByte)); ret.append(encodeVarInt(objectStoreId)); ret.append(encodeByte(metaDataType)); return ret; }
bool encodeUnopTerm(unopTermType *unopTerm) { nullEncode(unopTerm); return( encodeByte(UNOP_TAG) && encodeByte(byteOp(unopTerm->unop)) && encodeExpression(unopTerm->unopArgument) ); }
bool encodePreopTerm(preOpTermType *preopTerm) { nullEncode(preopTerm); return( encodeByte(PREOP_TAG) && encodeByte(byteOp(preopTerm->preOp)) && encodeExpression(preopTerm->preOpArgument) ); }
bool encodePostopTerm(postOpTermType *postopTerm) { nullEncode(postopTerm); return( encodeByte(POSTOP_TAG) && encodeByte(byteOp(postopTerm->postOp)) && encodeExpression(postopTerm->postOpArgument) ); }
bool encodeString(stringType *string) { if (!encodeByte(STRING_TAG)) return(FALSE); while (*string != '\0') { if (!encodeByte(*string++)) return(FALSE); } return(encodeByte('\0')); }
bool encodeBinopTerm(binopTermType *binopTerm) { nullEncode(binopTerm); return ( encodeByte(BINOP_TAG) && encodeByte(byteOp(binopTerm->binop)) && encodeExpression(binopTerm->leftArgument) && encodeExpression(binopTerm->rightArgument) ); }
bool encodeBlock(blockType *block) { if (!encodeByte(BLOCK_TAG)) return(FALSE); while (block != NULL) { if (!encodeStatement(block)) return(FALSE); block = block->nextStatement; } return(encodeByte(END_TAG)); }
bool encodeFunctionCall(functionCallTermType *functionCall) { functionDefinitionType *theFunction; int functionOrdinal; symbolInContextType *workingContext; operandListType *parameterList; nullEncode(functionCall); workingContext = getWorkingContext(functionCall->functionName); if (isFunction(workingContext)) { if (!encodeByte(FUNCTION_CALL_TAG)) return(FALSE); theFunction = (functionDefinitionType *)workingContext-> value->value; if (!encodeBigword(functionNumber(theFunction))) return(FALSE); } else if (isBuiltInFunction(workingContext)) { functionOrdinal = workingContext->value->value; if (builtInFunctionTable[functionOrdinal].isSpecialFunction) return(encodeValue((*builtInFunctionTable[ functionOrdinal].functionEntry)(functionCall-> parameters, NO_FIXUP))); if (!encodeByte(BUILTIN_FUNCTION_CALL_TAG)) return(FALSE); if (builtInFunctionTable[functionOrdinal].ordinal < 0) { error(BUILT_IN_FUNCTION_NOT_AVAILABLE_IN_OBJECT_ERROR, builtInFunctionTable[functionOrdinal]. functionName); return(FALSE); } else if (!encodeBigword(builtInFunctionTable[ functionOrdinal].ordinal)) { return(FALSE); } } else { error(NOT_A_FUNCTION_ERROR, symbName(functionCall-> functionName)); return(FALSE); } parameterList = functionCall->parameters; if (!encodeByte(countParameters(parameterList))) return(FALSE); while (parameterList != NULL) if (!encodeOperand(parameterList)) return(FALSE); else parameterList = parameterList->nextOperand; return(TRUE); }
bool encodeAssignmentTerm(binopTermType *assignmentTerm) { nullEncode(assignmentTerm); if ((assignmentKindType)assignmentTerm->binop != ASSIGN_ASSIGN) { error(FUNNY_ASSIGNMENT_KIND_IN_OBJECT_EXPRESSION_ERROR); return(FALSE); } return( encodeByte(BINOP_TAG) && encodeByte(byteOp(ASSIGN)) && encodeIdentifier(assignmentTerm->leftArgument) && encodeExpression(assignmentTerm->rightArgument) ); }
Vector<char> DatabaseMetaDataKey::encode(int64_t databaseId, MetaDataType metaDataType) { KeyPrefix prefix(databaseId, 0, 0); Vector<char> ret = prefix.encode(); ret.append(encodeByte(metaDataType)); return ret; }
Vector<char> SchemaVersionKey::encode() { KeyPrefix prefix(0, 0, 0); Vector<char> ret = prefix.encode(); ret.append(encodeByte(SchemaVersionTypeByte)); return ret; }
Vector<char> MaxDatabaseIdKey::encode() { KeyPrefix prefix(0, 0, 0); Vector<char> ret = prefix.encode(); ret.append(encodeByte(MaxDatabaseIdTypeByte)); return ret; }
bool encodeRelocatableNumber(numberTermType number) { return( encodeByte(RELOCATABLE_TAG) && encodeBigword(number) ); }
bool encodeFreturnStatement(freturnStatementBodyType *freturnStatement) { return( encodeByte(FRETURN_TAG) && encodeExpression(freturnStatement) ); }
bool encodeNumber(numberTermType number) { return( encodeByte(NUMBER_TAG) && encodeBigword(number) ); }
Vector<char> ObjectStoreNamesKey::encode(int64_t databaseId, const String& objectStoreName) { KeyPrefix prefix(databaseId, 0, 0); Vector<char> ret = prefix.encode(); ret.append(encodeByte(ObjectStoreNamesTypeByte)); ret.append(encodeStringWithLength(objectStoreName)); return ret; }
Vector<char> ObjectStoreFreeListKey::encode(int64_t databaseId, int64_t objectStoreId) { KeyPrefix prefix(databaseId, 0, 0); Vector<char> ret = prefix.encode(); ret.append(encodeByte(ObjectStoreFreeListTypeByte)); ret.append(encodeVarInt(objectStoreId)); return ret; }
Vector<char> DatabaseFreeListKey::encode(int64_t databaseId) { KeyPrefix prefix(0, 0, 0); Vector<char> ret = prefix.encode(); ret.append(encodeByte(DatabaseFreeListTypeByte)); ret.append(encodeVarInt(databaseId)); return ret; }
Vector<char> DatabaseNameKey::encode(const String& origin, const String& databaseName) { KeyPrefix prefix(0, 0, 0); Vector<char> ret = prefix.encode(); ret.append(encodeByte(DatabaseNameTypeByte)); ret.append(encodeStringWithLength(origin)); ret.append(encodeStringWithLength(databaseName)); return ret; }
bool encodeMdoUntilStatement(mdoUntilStatementBodyType *mdoUntilStatement) { return( encodeByte(MDOUNTIL_TAG) && encodeExpression(mdoUntilStatement->mdoUntilCondition) && encodeBlock(mdoUntilStatement->mdoUntilLoop) ); }
bool encodeAssertStatement(assertStatementBodyType *assertStatement) { return( encodeByte(ASSERT_TAG) && encodeExpression(assertStatement->condition) && encodeExpression(assertStatement->message) ); }
bool encodeMwhileStatement(mwhileStatementBodyType *mwhileStatement) { return( encodeByte(MWHILE_TAG) && encodeExpression(mwhileStatement->mwhileCondition) && encodeBlock(mwhileStatement->mwhileLoop) ); }
bool encodeMdefineStatement(defineStatementBodyType *mdefineStatement) { return( encodeByte(MDEFINE_TAG) && encodeIdentifier(mdefineStatement->theSymbol) && encodeExpression(mdefineStatement->theValue) ); }
Vector<char> IndexNamesKey::encode(int64_t databaseId, int64_t objectStoreId, const String& indexName) { KeyPrefix prefix(databaseId, 0, 0); Vector<char> ret = prefix.encode(); ret.append(encodeByte(IndexNamesKeyTypeByte)); ret.append(encodeVarInt(objectStoreId)); ret.append(encodeStringWithLength(indexName)); return ret; }
const char* extractEncodedIDBKey(const char* start, const char* limit, Vector<char>* result) { ASSERT(result); const char* p = start; if (p >= limit) return 0; unsigned char type = *p++; switch (type) { case kIDBKeyNullTypeByte: case kIDBKeyMinKeyTypeByte: *result = encodeByte(type); return p; case kIDBKeyArrayTypeByte: { int64_t length; p = decodeVarInt(p, limit, length); if (!p) return 0; if (length < 0) return 0; result->clear(); result->append(start, p - start); while (length--) { Vector<char> subkey; p = extractEncodedIDBKey(p, limit, &subkey); if (!p) return 0; result->append(subkey); } return p; } case kIDBKeyStringTypeByte: { int64_t length; p = decodeVarInt(p, limit, length); if (!p) return 0; if (p + length * 2 > limit) return 0; result->clear(); result->append(start, p - start + length * 2); return p + length * 2; } case kIDBKeyDateTypeByte: case kIDBKeyNumberTypeByte: if (p + sizeof(double) > limit) return 0; result->clear(); result->append(start, 1 + sizeof(double)); return p + sizeof(double); } ASSERT_NOT_REACHED(); return 0; }
bool encodeMifStatement(mifStatementBodyType *mifStatement) { return( encodeByte(MIF_TAG) && encodeExpression(mifStatement->mifCondition) && encodeBlock(mifStatement->mifConsequence) && encodeBlock(mifStatement->mifContinuation.mifBlockUnion) ); }
bool encodeMforStatement(mforStatementBodyType *mforStatement) { return( encodeByte(MFOR_TAG) && encodeExpression(mforStatement->initExpression) && encodeExpression(mforStatement->testExpression) && encodeExpression(mforStatement->incrExpression) && encodeBlock(mforStatement->forLoop) ); }
bool encodeBigword(int bigword) { int i; for (i=0; i<sizeof(int); ++i) { if (!encodeByte(bigword & 0xFF)) return(FALSE); bigword >>= 8; } return(TRUE); }
void encodeIDBKey(const IDBKey& key, Vector<char>& into) { size_t previousSize = into.size(); ASSERT(key.isValid()); switch (key.type()) { case IDBKey::InvalidType: case IDBKey::MinType: ASSERT_NOT_REACHED(); into.append(encodeByte(IDBKeyNullTypeByte)); return; case IDBKey::ArrayType: { into.append(encodeByte(IDBKeyArrayTypeByte)); size_t length = key.array().size(); into.append(encodeVarInt(length)); for (size_t i = 0; i < length; ++i) encodeIDBKey(*key.array()[i], into); ASSERT_UNUSED(previousSize, into.size() > previousSize); return; } case IDBKey::StringType: into.append(encodeByte(IDBKeyStringTypeByte)); into.append(encodeStringWithLength(key.string())); ASSERT_UNUSED(previousSize, into.size() > previousSize); return; case IDBKey::DateType: into.append(encodeByte(IDBKeyDateTypeByte)); into.append(encodeDouble(key.date())); ASSERT_UNUSED(previousSize, into.size() - previousSize == 9); return; case IDBKey::NumberType: into.append(encodeByte(IDBKeyNumberTypeByte)); into.append(encodeDouble(key.number())); ASSERT_UNUSED(previousSize, into.size() - previousSize == 9); return; } ASSERT_NOT_REACHED(); }