bool encodeValue(valueType *value) { switch (value->kindOfValue) { case ABSOLUTE_VALUE: return(encodeNumber(value->value)); case RELOCATABLE_VALUE: return(encodeRelocatableNumber(value->value)); case OPERAND_VALUE: return(encodeOperand(value->value)); case STRING_VALUE: return(encodeString(value->value)); case CONDITION_VALUE: return(encodeCondition(value->value)); case DATA_VALUE: case BSS_VALUE: case STRUCT_VALUE: case FIELD_VALUE: case MACRO_VALUE: case UNDEFINED_VALUE: case FUNCTION_VALUE: case BLOCK_VALUE: case BUILT_IN_FUNCTION_VALUE: case ARRAY_VALUE: case FAIL: error(WRONG_KIND_OF_VALUE_IN_OBJECT_EXPRESSION_ERROR, valueKindString(value->kindOfValue)); return(FALSE); } }
void GoogleEncode::addUnsignedNumber(unsigned value) { unsigned num; if (delta) { num = value - last_values[last_dim % dimension]; last_values[last_dim % dimension] = value; last_dim += 1; } else { num = value; } encodeNumber(num); }
void PolylineCompressor::encodeVectorSignedNumber(std::vector<int> &numbers, std::string &output) const { const unsigned end = static_cast<unsigned>(numbers.size()); for (unsigned i = 0; i < end; ++i) { numbers[i] <<= 1; if (numbers[i] < 0) { numbers[i] = ~(numbers[i]); } } for (const int number : numbers) { encodeNumber(number, output); } }
void GoogleEncode::addDouble(double value) { int num; if (delta) { num = floor_value(value) - last_values[last_dim % dimension]; last_values[last_dim % dimension] = floor_value(value); last_dim += 1; } else { num = floor_value(value); } unsigned sgn_num = static_cast<unsigned>(num) << 1; if (num < 0) { sgn_num = ~sgn_num; } encodeNumber(sgn_num); }
void GoogleEncode::addSignedNumber(int value) { int num; if (delta) { num = value - last_values[last_dim % dimension]; last_values[last_dim % dimension] = value; last_dim += 1; } else { num = value; } unsigned sgn_num = static_cast<unsigned>(num) << 1; if (num < 0) { sgn_num = ~sgn_num; } encodeNumber(sgn_num); }
/* * Given an OID in dotted-decimal string representation, convert to binary * DER format. Returns a pointer in outOid which the caller must free(), * as well as the length of the data in outLen. * Function returns 0 if successful, non-zero otherwise. */ static int encodeOid( const unsigned char *inStr, unsigned char **outOid, unsigned int *outLen) { unsigned char **digits = NULL; /* array of char * from encodeNumber */ unsigned *numDigits = NULL; /* array of unsigned from encodeNumber */ CFIndex digit; unsigned numDigitBytes; /* total #of output chars */ unsigned char firstByte; unsigned char *outP; CFIndex numsToProcess; CFStringRef oidStr = NULL; CFArrayRef argvRef = NULL; int num, result = 1; CFIndex argc; /* parse input string into array of substrings */ if (!inStr || !outOid || !outLen) goto cleanExit; oidStr = CFStringCreateWithCString(NULL, (const char *)inStr, kCFStringEncodingASCII); if (!oidStr) goto cleanExit; argvRef = CFStringCreateArrayBySeparatingStrings(NULL, oidStr, CFSTR(".")); if (!argvRef) goto cleanExit; argc = CFArrayGetCount(argvRef); if (argc < 3) goto cleanExit; /* first two numbers in OID munge together */ num = cfStringToNumber((CFStringRef)CFArrayGetValueAtIndex(argvRef, 0)); if (num < 0) goto cleanExit; firstByte = (40 * num); num = cfStringToNumber((CFStringRef)CFArrayGetValueAtIndex(argvRef, 1)); if (num < 0) goto cleanExit; firstByte += num; numDigitBytes = 1; numsToProcess = argc - 2; if(numsToProcess > 0) { /* skip this loop in the unlikely event that input is only two numbers */ digits = (unsigned char **) malloc(numsToProcess * sizeof(unsigned char *)); numDigits = (unsigned *) malloc(numsToProcess * sizeof(unsigned)); for(digit=0; digit<numsToProcess; digit++) { num = cfStringToNumber((CFStringRef)CFArrayGetValueAtIndex(argvRef, digit+2)); if (num < 0) goto cleanExit; numDigits[digit] = encodeNumber(num, &digits[digit]); numDigitBytes += numDigits[digit]; } } *outLen = (2 + numDigitBytes); *outOid = outP = (unsigned char *) malloc(*outLen); *outP++ = 0x06; *outP++ = numDigitBytes; *outP++ = firstByte; for(digit=0; digit<numsToProcess; digit++) { unsigned int byteDex; for(byteDex=0; byteDex<numDigits[digit]; byteDex++) { *outP++ = digits[digit][byteDex]; } } if(digits) { for(digit=0; digit<numsToProcess; digit++) { free(digits[digit]); } free(digits); free(numDigits); } result = 0; cleanExit: if (oidStr) CFRelease(oidStr); if (argvRef) CFRelease(argvRef); return result; }
//encode all descriptors of the limbs void Limbs::encodeLimbs(unsigned int number, std :: string thickness) { //get numerical value per descriptor to encode encodeNumber(number); encodeThickness(thicknessK[thickness]); }
Limbs::Limbs(Encoding &g) :genome(g) { //create Traits Trait spindly(1, -3, 3, "spindly"); Trait thin(1, -2, 1, "thin"); Trait thick(-2, 3, 0, "thick"); Trait round(3, -1, -1, "round"); Trait zero(0, 0, 3, "0"); Trait one(1, 1, 3, "1"); Trait two(3, 1, -3, "2"); Trait three(-1, 1, 3, "3"); Trait four(3, 1, -3, "4"); Trait five(-1, 1, 3, "5"); Trait six(2, 1, -3, "6"); Trait seven(-2, 2, 3, "7"); Trait eight(0, 3, 2, "8"); Trait nine(-3, 2, 3, "9"); Trait ten(-2, 3, 2, "10"); Trait eleven(-3, 2, 3, "11"); Trait twelve(-3, 3, 2, "12"); Trait thirteen(-3, 2, 3, "13"); Trait fourteen(-3, 3, 3, "14"); Trait fifteen(-3, 2, 3, "15"); //create all maps if (thicknessK.empty() ) { thicknessK["spindly"] = 0; thicknessK["thin"] = 1; thicknessK["thick"] = 2; thicknessK["round"] = 3; thicknessM[0] = spindly; thicknessM[1] = thin; thicknessM[2] = thick; thicknessM[3] = round; numM[0] = zero; numM[1] = one; numM[2] = two; numM[3] = three; numM[4] = four; numM[5] = five; numM[6] = six; numM[7] = seven; numM[8] = eight; numM[9] = nine; numM[10] = ten; numM[11] = eleven; numM[12] = twelve; numM[13] = thirteen; numM[14] = fourteen; numM[15] = fifteen; } //decode the number of limbs so that there can //only be a non-zero even number of them number = decodeNumber(); int numValue = std::stoi(number); if (numValue % 2 != 0) { encodeNumber(numValue + 1); number = decodeNumber(); } if (numValue == 0) { encodeNumber(2); number = decodeNumber(); } thickness = decodeThickness(); }
bool encodeExpression(expressionType *expression) { nullEncode(expression); switch (expression->kindOfTerm) { case ARRAY_EXPR: error(ARRAY_TERM_IN_OBJECT_EXPRESSION_ERROR); return(FALSE); break; case ASSIGN_EXPR: return(encodeAssignmentTerm(expression->expressionTerm.binopUnion)); break; case BINOP_EXPR: return(encodeBinopTerm(expression->expressionTerm.binopUnion)); break; case CONDITION_CODE_EXPR: return(encodeCondition(expression->expressionTerm.conditionTypeUnion)); break; case FUNCTION_CALL_EXPR: return(encodeFunctionCall(expression->expressionTerm.functionCallUnion)); break; case HERE_EXPR: return(encodeHere()); break; case IDENTIFIER_EXPR: return(encodeIdentifier(expression->expressionTerm.identifierUnion)); break; case NUMBER_EXPR: return(encodeNumber(expression->expressionTerm.numberUnion)); break; case POSTOP_EXPR: return(encodePostopTerm(expression->expressionTerm.postOpUnion)); break; case PREOP_EXPR: return(encodePreopTerm(expression->expressionTerm.preOpUnion)); break; case SUBEXPRESSION_EXPR: encodeExpression(expression->expressionTerm.expressionUnion); break; case STRING_EXPR: return(encodeString(expression->expressionTerm.stringUnion)); break; case UNOP_EXPR: return(encodeUnopTerm(expression->expressionTerm.unopUnion)); break; case VALUE_EXPR: return(encodeValue(expression->expressionTerm.valueUnion)); break; default: botch("encodeExpression: funny expression kind %d\n", expression->kindOfTerm); break; } }