void Message::setValue(const AutoAnyReference &value, const Signature& sig, ObjectHost* context, StreamContext* streamContext) { cow(); Signature effective = value.type()->signature(); if (effective != sig) { TypeInterface* ti = TypeInterface::fromSignature(sig); if (!ti) qiLogWarning() << "setValue(): cannot construct type for signature " << sig.toString(); std::pair<AnyReference, bool> conv = value.convert(ti); if (!conv.first.type()) { std::stringstream ss; ss << "Setvalue(): failed to convert effective value " << value.type()->signature().toString() << " to expected type " << sig.toString() << '(' << ti->infoString() << ')'; qiLogWarning() << ss.str(); setType(qi::Message::Type_Error); setError(ss.str()); } else encodeBinary(&_p->buffer, conv.first, boost::bind(serializeObject, _1, context), streamContext); if (conv.second) conv.first.destroy(); } else if (value.type()->kind() != qi::TypeKind_Void) { encodeBinary(&_p->buffer, value, boost::bind(serializeObject, _1, context), streamContext); } }
//convert args then call setValues void Message::setValues(const std::vector<qi::AnyReference>& in, const qi::Signature& expectedSignature, ObjectHost* context, StreamContext* streamContext) { qi::Signature argsSig = qi::makeTupleSignature(in, false); if (expectedSignature == argsSig) { setValues(in, context, streamContext); return; } if (expectedSignature == "m") { /* We need to send a dynamic containing the value tuple to push the * signature. This wraps correctly without copying the data. */ std::vector<qi::TypeInterface*> types; std::vector<void*> values; types.resize(in.size()); values.resize(in.size()); for (unsigned i=0; i<in.size(); ++i) { types[i] = in[i].type(); values[i] = in[i].rawValue(); } AnyReference tuple = makeGenericTuplePtr(types, values); AnyValue val(tuple, false, false); encodeBinary(&_p->buffer, AnyReference::from(val), boost::bind(serializeObject, _1, context), streamContext); return; } /* This check does not makes sense for this transport layer who does not care, * But it checks a general rule that is true for all the messages we use and * it can help catch many mistakes. */ if (expectedSignature.type() != Signature::Type_Tuple) throw std::runtime_error("Expected a tuple, got " + expectedSignature.toString()); AnyReferenceVector nargs(in); SignatureVector src = argsSig.children(); SignatureVector dst = expectedSignature.children(); if (src.size() != dst.size()) throw std::runtime_error("remote call: signature size mismatch"); SignatureVector::iterator its = src.begin(), itd = dst.begin(); boost::dynamic_bitset<> allocated(nargs.size()); for (unsigned i = 0; i< nargs.size(); ++i, ++its, ++itd) { if (*its != *itd) { ::qi::TypeInterface* target = ::qi::TypeInterface::fromSignature(*itd); if (!target) throw std::runtime_error("remote call: Failed to obtain a type from signature " + (*itd).toString()); std::pair<AnyReference, bool> c = nargs[i].convert(target); if (!c.first.type()) { throw std::runtime_error( _QI_LOG_FORMAT("remote call: failed to convert argument %s from %s to %s", i, (*its).toString(), (*itd).toString())); } nargs[i] = c.first; allocated[i] = c.second; } } setValues(nargs, context, streamContext); for (unsigned i = 0; i< nargs.size(); ++i) if (allocated[i]) nargs[i].destroy(); }
void Message::setValues(const std::vector<qi::AnyReference>& values, ObjectHost* context, StreamContext* streamContext) { cow(); SerializeObjectCallback scb = boost::bind(serializeObject, _1, context); for (unsigned i = 0; i < values.size(); ++i) encodeBinary(&_p->buffer, values[i], scb, streamContext); }
//============================================================================== int performCommandLine (const String& commandLine) { StringArray args; args.addTokens (commandLine, true); args.trim(); if (findArgument (args, "--lf") || findArgument (args, "-lf")) preferredLinefeed = "\n"; String command (args[0]); try { if (matchArgument (command, "help")) { showHelp(); return 0; } if (matchArgument (command, "h")) { showHelp(); return 0; } if (matchArgument (command, "resave")) { resaveProject (args, false); return 0; } if (matchArgument (command, "resave-resources")) { resaveProject (args, true); return 0; } if (matchArgument (command, "get-version")) { getVersion (args); return 0; } if (matchArgument (command, "set-version")) { setVersion (args); return 0; } if (matchArgument (command, "bump-version")) { bumpVersion (args); return 0; } if (matchArgument (command, "git-tag-version")) { gitTag (args); return 0; } if (matchArgument (command, "buildmodule")) { buildModules (args, false); return 0; } if (matchArgument (command, "buildallmodules")) { buildModules (args, true); return 0; } if (matchArgument (command, "status")) { showStatus (args); return 0; } if (matchArgument (command, "trim-whitespace")) { cleanWhitespace (args, false); return 0; } if (matchArgument (command, "remove-tabs")) { cleanWhitespace (args, true); return 0; } if (matchArgument (command, "tidy-divider-comments")) { tidyDividerComments (args); return 0; } if (matchArgument (command, "fix-broken-include-paths")) { fixRelativeIncludePaths (args); return 0; } if (matchArgument (command, "obfuscated-string-code")) { generateObfuscatedStringCode (args); return 0; } if (matchArgument (command, "encode-binary")) { encodeBinary (args); return 0; } if (matchArgument (command, "trans")) { scanFoldersForTranslationFiles (args); return 0; } if (matchArgument (command, "trans-finish")) { createFinishedTranslationFile (args); return 0; } if (matchArgument (command, "set-global-search-path")) { setGlobalPath (args); return 0; } if (matchArgument (command, "create-project-from-pip")) { createProjectFromPIP (args); return 0; } } catch (const CommandLineError& error) { std::cout << error.message << std::endl << std::endl; return 1; } return commandLineNotPerformed; }
CFX_WideString CBC_PDF417HighLevelEncoder::encodeHighLevel( CFX_WideString wideMsg, Compaction compaction, int32_t& e) { CFX_ByteString bytes; CBC_UtilCodingConvert::UnicodeToUTF8(wideMsg, bytes); CFX_WideString msg; int32_t len = bytes.GetLength(); for (int32_t i = 0; i < len; i++) { FX_WCHAR ch = (FX_WCHAR)(bytes.GetAt(i) & 0xff); if (ch == '?' && bytes.GetAt(i) != '?') { e = BCExceptionCharactersOutsideISO88591Encoding; return CFX_WideString(); } msg += ch; } CFX_ByteArray byteArr; for (int32_t k = 0; k < bytes.GetLength(); k++) { byteArr.Add(bytes.GetAt(k)); } CFX_WideString sb; len = msg.GetLength(); int32_t p = 0; int32_t textSubMode = SUBMODE_ALPHA; if (compaction == TEXT) { encodeText(msg, p, len, sb, textSubMode); } else if (compaction == BYTES) { encodeBinary(&byteArr, p, byteArr.GetSize(), BYTE_COMPACTION, sb); } else if (compaction == NUMERIC) { sb += (FX_WCHAR)LATCH_TO_NUMERIC; encodeNumeric(msg, p, len, sb); } else { int32_t encodingMode = LATCH_TO_TEXT; while (p < len) { int32_t n = determineConsecutiveDigitCount(msg, p); if (n >= 13) { sb += (FX_WCHAR)LATCH_TO_NUMERIC; encodingMode = NUMERIC_COMPACTION; textSubMode = SUBMODE_ALPHA; encodeNumeric(msg, p, n, sb); p += n; } else { int32_t t = determineConsecutiveTextCount(msg, p); if (t >= 5 || n == len) { if (encodingMode != TEXT_COMPACTION) { sb += (FX_WCHAR)LATCH_TO_TEXT; encodingMode = TEXT_COMPACTION; textSubMode = SUBMODE_ALPHA; } textSubMode = encodeText(msg, p, t, sb, textSubMode); p += t; } else { int32_t b = determineConsecutiveBinaryCount(msg, &byteArr, p, e); BC_EXCEPTION_CHECK_ReturnValue(e, (FX_WCHAR)' '); if (b == 0) { b = 1; } if (b == 1 && encodingMode == TEXT_COMPACTION) { encodeBinary(&byteArr, p, 1, TEXT_COMPACTION, sb); } else { encodeBinary(&byteArr, p, b, encodingMode, sb); encodingMode = BYTE_COMPACTION; textSubMode = SUBMODE_ALPHA; } p += b; } } } } return sb; }