bool ArgumentCoder<DragData>::decode(Decoder& decoder, DragData& dragData)
{
    IntPoint clientPosition;
    if (!decoder.decode(clientPosition))
        return false;

    IntPoint globalPosition;
    if (!decoder.decode(globalPosition))
        return false;

    uint64_t sourceOperationMask;
    if (!decoder.decode(sourceOperationMask))
        return false;

    uint64_t flags;
    if (!decoder.decode(flags))
        return false;

    bool hasPlatformData;
    if (!decoder.decode(hasPlatformData))
        return false;

    RefPtr<DataObjectGtk> platformData;
    if (hasPlatformData) {
        if (!decodeDataObject(decoder, platformData))
            return false;
    }

    dragData = DragData(platformData.leakRef(), clientPosition, globalPosition, static_cast<DragOperation>(sourceOperationMask),
                        static_cast<DragApplicationFlags>(flags));

    return true;
}
 void decode(Decoder& d, Reporter& reporter) override {
   String groupStr;
   d.decode(groupStr);
   groupByValue = std::string(groupStr);
   d.decode(total);
   d.decode(count);
 }
bool Coder<WebCore::CertificateInfo>::decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo)
{
    bool hasCertificate;
    if (!decoder.decode(hasCertificate))
        return false;

    if (!hasCertificate)
        return true;

    uint64_t size = 0;
    if (!decoder.decode(size))
        return false;

    Vector<uint8_t> vector(size);
    if (!decoder.decodeFixedLengthData(vector.data(), vector.size()))
        return false;

    GByteArray* certificateData = g_byte_array_sized_new(vector.size());
    certificateData = g_byte_array_append(certificateData, vector.data(), vector.size());
    GRefPtr<GByteArray> certificateBytes = adoptGRef(certificateData);

    GTlsBackend* backend = g_tls_backend_get_default();
    GRefPtr<GTlsCertificate> certificate = adoptGRef(G_TLS_CERTIFICATE(g_initable_new(
        g_tls_backend_get_certificate_type(backend), 0, 0, "certificate", certificateBytes.get(), nullptr)));
    certificateInfo.setCertificate(certificate.get());

    uint32_t tlsErrors;
    if (!decoder.decode(tlsErrors))
        return false;
    certificateInfo.setTLSErrors(static_cast<GTlsCertificateFlags>(tlsErrors));

    return true;
}
Example #4
0
bool Coder<WebCore::HTTPHeaderMap>::decode(Decoder& decoder, WebCore::HTTPHeaderMap& headers)
{
    uint64_t headersSize;
    if (!decoder.decode(headersSize))
        return false;
    for (uint64_t i = 0; i < headersSize; ++i) {
        String name;
        if (!decoder.decode(name))
            return false;
        String value;
        if (!decoder.decode(value))
            return false;
        headers.add(name, value);
    }
    return true;
}
Example #5
0
bool ArgumentCoder<CString>::decode(Decoder& decoder, CString& result)
{
    uint32_t length;
    if (!decoder.decode(length))
        return false;

    if (length == std::numeric_limits<uint32_t>::max()) {
        // This is the null string.
        result = CString();
        return true;
    }

    // Before allocating the string, make sure that the decoder buffer is big enough.
    if (!decoder.bufferIsLargeEnoughToContain<char>(length)) {
        decoder.markInvalid();
        return false;
    }

    char* buffer;
    CString string = CString::newUninitialized(length, buffer);
    if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(buffer), length, 1))
        return false;

    result = string;
    return true;
}
bool SubresourceInfo::decode(Decoder& decoder, SubresourceInfo& info)
{
    if (!decoder.decode(info.m_isTransient))
        return false;

    if (info.m_isTransient)
        return true;

    if (!decoder.decode(info.m_firstPartyForCookies))
        return false;

    if (!decoder.decode(info.m_requestHeaders))
        return false;

    return true;
}
Example #7
0
inline void
invoke_reuse_helper(Encoder encoder, Decoder decoder)
{
    std::vector<uint8_t> payload(encoder->payload_size());

    std::vector<uint8_t> data_in = random_vector(encoder->block_size());
    sak::mutable_storage storage_in = sak::storage(data_in);

    encoder->set_symbols(storage_in);

    // Set the encoder non-systematic
    if(kodo::is_systematic_encoder(encoder))
        kodo::set_systematic_off(encoder);

    while( !decoder->is_complete() )
    {
        uint32_t payload_used = encoder->encode( &payload[0] );
        EXPECT_TRUE(payload_used <= encoder->payload_size());

        decoder->decode( &payload[0] );
    }

    std::vector<uint8_t> data_out(decoder->block_size(), '\0');
    decoder->copy_symbols(sak::storage(data_out));

    EXPECT_TRUE(std::equal(data_out.begin(),
                           data_out.end(),
                           data_in.begin()));

}
Example #8
0
bool ArgumentCoder<AtomicString>::decode(Decoder& decoder, AtomicString& atomicString)
{
    String string;
    if (!decoder.decode(string))
        return false;

    atomicString = string;
    return true;
}
Example #9
0
bool ArgumentCoder<std::chrono::system_clock::time_point>::decode(Decoder& decoder, std::chrono::system_clock::time_point& result)
{
    int64_t time;
    if (!decoder.decode(time))
        return false;

    result = std::chrono::system_clock::time_point(std::chrono::system_clock::duration(static_cast<std::chrono::system_clock::rep>(time)));
    return true;
}
Example #10
0
int
decode()
{
    Decoder* dec = Decoder::GetDecoder();
    if (!dec)
        return -1;
    int ret = dec->decode();
    delete dec;
    return ret;
}
bool StringReference::decode(Decoder& decoder, StringReference& result)
{
    DataReference dataReference;
    if (!decoder.decode(dataReference))
        return false;

    result.m_data = reinterpret_cast<const char*>(dataReference.data());
    result.m_size = dataReference.size();

    return true;
}
bool Coder<String>::decode(Decoder& decoder, String& result)
{
    uint32_t length;
    if (!decoder.decode(length))
        return false;

    if (length == std::numeric_limits<uint32_t>::max()) {
        // This is the null string.
        result = String();
        return true;
    }

    bool is8Bit;
    if (!decoder.decode(is8Bit))
        return false;

    if (is8Bit)
        return decodeStringText<LChar>(decoder, length, result);
    return decodeStringText<UChar>(decoder, length, result);
}
Example #13
0
Item::Item(Decoder& decoder, Engine* engine, Item* owner) : engine_(engine), owner_(owner)
{
	decoder.decode(typeID_);
	decoder.decode(groupID_);
	decoder.decode(categoryID_);

	{
		AttributesMap::size_type size;
		decoder.decode(size);
		for (AttributesMap::size_type i = 0; i < size; i++)
		{
			Attribute* attribute = new Attribute(decoder, engine, this);
			attributes_[attribute->getAttributeID()] = attribute;
		}
	}
	{
		EffectsList::size_type size;
		decoder.decode(size);
		for (EffectsList::size_type i = 0; i < size; i++)
		{
			TypeID effectID;
			decoder.decode(effectID);
			effects_.push_back(Effect::getEffect(engine_, effectID));
		}
	}
}
static bool decodeCFData(Decoder& decoder, RetainPtr<CFDataRef>& data)
{
    uint64_t size = 0;
    if (!decoder.decode(size))
        return false;

    Vector<uint8_t> vector(size);
    if (!decoder.decodeFixedLengthData(vector.data(), vector.size()))
        return false;

    data = adoptCF(CFDataCreate(nullptr, vector.data(), vector.size()));
    return true;
}
 /**
  * \brief Decode from XDQP stream
  */
 void decode(Decoder& d, Reporter& reporter) {
   try {
     int size;
     d.decode(size);
     IInterimResult* interim;
     for (long i = 0;i < size;i++) {
       // decode all interim results
       interim = resultTypeRef();
       interim->decode(d,reporter);
     }
   } catch (std::exception& ex) {
     reporter.error(("Exception in decode(): " + std::string(ex.what())).c_str());
   }
 }
bool Coder<WebCore::CertificateInfo>::decode(Decoder& decoder, WebCore::CertificateInfo& certificateInfo)
{
    uint64_t certificateSize;
    if (!decoder.decode(certificateSize))
        return false;
    Vector<uint8_t> data(certificateSize);
    if (!decoder.decodeFixedLengthData(data.data(), data.size()))
        return false;
    IPC::ArgumentDecoder argumentDecoder(data.data(), data.size());
    if (!argumentDecoder.decode(certificateInfo)) {
        decoder.markInvalid();
        return false;
    }
    return true;
}
static bool decodeGKeyFile(Decoder& decoder, GUniquePtr<GKeyFile>& keyFile)
{
    DataReference dataReference;
    if (!decoder.decode(dataReference))
        return false;

    if (!dataReference.size())
        return true;

    keyFile.reset(g_key_file_new());
    if (!g_key_file_load_from_data(keyFile.get(), reinterpret_cast<const gchar*>(dataReference.data()), dataReference.size(), G_KEY_FILE_NONE, 0)) {
        keyFile.reset();
        return false;
    }

    return true;
}
static bool decodeCertificateChain(Decoder& decoder, RetainPtr<CFArrayRef>& certificateChain)
{
    uint64_t size;
    if (!decoder.decode(size))
        return false;

    auto array = adoptCF(CFArrayCreateMutable(0, 0, &kCFTypeArrayCallBacks));

    for (size_t i = 0; i < size; ++i) {
        RetainPtr<CFDataRef> data;
        if (!decodeCFData(decoder, data))
            return false;

        auto certificate = adoptCF(SecCertificateCreateWithData(0, data.get()));
        CFArrayAppendValue(array.get(), certificate.get());
    }

    certificateChain = WTFMove(array);
    return true;
}
static bool decodeSecTrustRef(Decoder& decoder, RetainPtr<SecTrustRef>& result)
{
    bool hasTrust;
    if (!decoder.decode(hasTrust))
        return false;

    if (!hasTrust)
        return true;

    RetainPtr<CFDataRef> trustData;
    if (!decodeCFData(decoder, trustData))
        return false;

    auto trust = adoptCF(SecTrustDeserialize(trustData.get(), nullptr));
    if (!trust)
        return false;

    result = WTFMove(trust);
    return true;
}
Example #20
0
QString SourceFile::getCode()
{
    if(interpreter)
    {
        KHTMLPart *part = ::qt_cast< KHTMLPart * >(static_cast< ScriptInterpreter * >(interpreter)->part());
        if(part && url == part->url().url() && KHTMLPageCache::self()->isValid(part->cacheId()))
        {
            Decoder *decoder = part->createDecoder();
            QByteArray data;
            QDataStream stream(data, IO_WriteOnly);
            KHTMLPageCache::self()->saveData(part->cacheId(), &stream);
            QString str;
            if(data.size() == 0)
                str = "";
            else
                str = decoder->decode(data.data(), data.size()) + decoder->flush();
            delete decoder;
            return str;
        }
    }

    return code;
}
static bool decodeImage(Decoder& decoder, GRefPtr<GdkPixbuf>& pixbuf)
{
    ShareableBitmap::Handle handle;
    if (!decoder.decode(handle))
        return false;

    RefPtr<ShareableBitmap> bitmap = ShareableBitmap::create(handle);
    if (!bitmap)
        return false;

    RefPtr<Image> image = bitmap->createImage();
    if (!image)
        return false;

    RefPtr<cairo_surface_t> surface = image->nativeImageForCurrentFrame();
    if (!surface)
        return false;

    pixbuf = adoptGRef(gdk_pixbuf_get_from_surface(surface.get(), 0, 0, cairo_image_surface_get_width(surface.get()), cairo_image_surface_get_height(surface.get())));
    if (!pixbuf)
        return false;

    return true;
}
Example #22
0
bool Generator::getAndQueueEventInt(bool block)
{
   bool result = true;
   //static ArchEvent *arch_event = NULL;
   ArchEvent* arch_event = getCachedEvent();
   vector<Event::ptr> events;
   vector<ArchEvent *> archEvents;

   if (isExitingState()) {
      pthrd_printf("Generator exiting before processWait\n");
      result = false;
      goto done;
   }
   setState(process_blocked);
   result = processWait(block);
   if (isExitingState()) {
      pthrd_printf("Generator exiting after processWait\n");
      result = false;
      goto done;
   }
   if (!result) {
	   pthrd_printf("Generator exiting after processWait returned false\n");
	   result = false;
      goto done;
   }
   result = plat_continue(arch_event);
   if(!result) {
	   pthrd_printf("Generator exiting after plat_continue returned false\n");
	   result = false;
	   goto done;
   }
   setState(system_blocked);

   pthrd_printf("About to getEvent()\n");
   result = getMultiEvent(block, archEvents);
   pthrd_printf("Got event\n");
   if (isExitingState()) {
      pthrd_printf("Generator exiting after getEvent\n");
      result = false;
      goto done;
   }
   if (!result) {
      pthrd_printf("Error. Unable to recieve event\n");
      result = false;
      goto done;
   }

   setState(decoding);
   //mbox()->lock_queue();
   ProcPool()->condvar()->lock();

   for (vector<ArchEvent *>::iterator i = archEvents.begin(); i != archEvents.end(); i++) {
	   arch_event = *i;
      for (decoder_set_t::iterator j = decoders.begin(); j != decoders.end(); j++) {
         Decoder *decoder = *j;
         bool result = decoder->decode(arch_event, events);
         if (result)
            break;
      }
   }

   setState(statesync);
   for (vector<Event::ptr>::iterator i = events.begin(); i != events.end(); i++) {
      Event::ptr event = *i;
	  if(event) {
	      event->getProcess()->llproc()->updateSyncState(event, true);
	  }
   }

   ProcPool()->condvar()->unlock();

   setState(queueing);
   for (vector<Event::ptr>::iterator i = events.begin(); i != events.end(); ++i) {
      mbox()->enqueue(*i);
      Generator::cb_lock->lock();
      for (set<gen_cb_func_t>::iterator j = CBs.begin(); j != CBs.end(); ++j) {
         (*j)();
      }
      Generator::cb_lock->unlock(); 
   }
   //mbox()->unlock_queue();


   result = true;
 done:
   setState(none);
   setCachedEvent(arch_event);
   return result;
}
Example #23
0
Xchar ExternalInputSource::fill(Messenger &mgr)
{
  ASSERT(cur() == end());
  while (end() >= bufLim_) {
    // need more data
    while (so_ == 0) {
      if (soIndex_ >= sov_.size())
	return eE;
      if (soIndex_ > 0)
	info_->noteStorageObjectEnd(bufLimOffset_ - (bufLim_ - end()));
      const StorageObjectSpec &spec = info_->spec(soIndex_);
      if (mayNotExist_) {
	NullMessenger nullMgr;
	sov_[soIndex_]
	  = spec.storageManager->makeStorageObject(spec.specId, spec.baseId,
						   spec.search,
						   mayRewind_, nullMgr,
						   info_->id(soIndex_));
      }
      else
	sov_[soIndex_]
	  = spec.storageManager->makeStorageObject(spec.specId, spec.baseId,
						   spec.search,
						   mayRewind_, mgr,
						   info_->id(soIndex_));
      so_ = sov_[soIndex_].pointer();
      if (so_) {
	decoder_ = spec.codingSystem->makeDecoder();
	info_->setDecoder(soIndex_, decoder_);
	zapEof_ = spec.zapEof;
	switch (spec.records) {
	case StorageObjectSpec::asis:
	  recordType_ = asis;
	  insertRS_ = false;
	  break;
	case StorageObjectSpec::cr:
	  recordType_ = cr;
	  break;
	case StorageObjectSpec::lf:
	  recordType_ = lf;
	  break;
	case StorageObjectSpec::crlf:
	  recordType_ = crlf;
	  break;
	case StorageObjectSpec::find:
	  recordType_ = unknown;
	  break;
	default:
	  CANNOT_HAPPEN();
	}
	soIndex_++;
	readSize_ = so_->getBlockSize();
	nLeftOver_ = 0;
	break;
      }
      else
	setAccessError();
      soIndex_++;
    }

    size_t keepSize = end() - start();
    const size_t align = sizeof(int)/sizeof(Char);
    size_t readSizeChars = (readSize_ + (sizeof(Char) - 1))/sizeof(Char);
    readSizeChars = roundUp(readSizeChars, align);
    size_t neededSize;		// in Chars
    size_t startOffset;
    // compute neededSize and readSize
    unsigned minBytesPerChar = decoder_->minBytesPerChar();
    if (nLeftOver_ == 0 && minBytesPerChar >= sizeof(Char)) {
      // In this case we want to do decoding in place.
      // FIXME It might be a win on some systems (Irix?) to arrange that the
      // read buffer is on a page boundary.

      if (keepSize >= size_t(-1)/sizeof(Char) - (align - 1) - insertRS_)
	abort();			// FIXME throw an exception
      
      // Now size_t(-1)/sizeof(Char) - (align - 1) - insertRS_ - keepSize > 0
      if (readSizeChars
	  > size_t(-1)/sizeof(Char) - (align - 1) - insertRS_ - keepSize)
	abort();
      neededSize = roundUp(readSizeChars + keepSize + insertRS_, align);
      startOffset = ((neededSize > bufSize_ ? neededSize : bufSize_)
		     - readSizeChars - insertRS_ - keepSize);
    }
    else {
      // Needs to be room for everything before decoding.
      neededSize = (keepSize + insertRS_ + readSizeChars
		    + (nLeftOver_ + sizeof(Char) - 1)/sizeof(Char));
      // Also must be room for everything after decoding.
      size_t neededSize2
	= (keepSize + insertRS_
	   // all the converted characters
	   + (nLeftOver_ + readSize_)/minBytesPerChar
	   // enough Chars to contain left over bytes
	   + ((readSize_ % minBytesPerChar + sizeof(Char) - 1)
	      / sizeof(Char)));
      if (neededSize2 > neededSize)
	neededSize = neededSize2;
      neededSize = roundUp(neededSize, align);
      if (neededSize > size_t(-1)/sizeof(Char))
	abort();
      startOffset = 0;
    }
    if (bufSize_ < neededSize)
      reallocateBuffer(neededSize);
    Char *newStart = buf_ + startOffset;
    if (newStart != start() && keepSize > 0)
      memmove(newStart, start(), keepSize*sizeof(Char));
    char *bytesStart = (char *)(buf_ + bufSize_ - readSizeChars) - nLeftOver_;
    if (nLeftOver_ > 0 && leftOver_ != bytesStart)
      memmove(bytesStart, leftOver_, nLeftOver_);
    moveStart(newStart);
    bufLim_ = end();

    size_t nread;
    if (so_->read((char *)(buf_ + bufSize_ - readSizeChars), readSize_,
		  mgr, nread)) {
      if (nread > 0) {
	const char *bytesEnd = bytesStart + nLeftOver_ + nread;
	size_t nChars = decoder_->decode((Char *)end() + insertRS_,
					 bytesStart,
					 nLeftOver_ + nread
					 - (zapEof_ && bytesEnd[-1] == EOFCHAR),
					 &leftOver_);
	nLeftOver_ = bytesEnd - leftOver_;
	if (nChars > 0) {
	  if (insertRS_) {
	    noteRS();
	    *(Char *)end() = RS;
	    advanceEnd(end() + 1);
	    insertRS_ = false;
	    bufLim_ += 1;
	    bufLimOffset_ += 1;
	  }
	  bufLim_ += nChars;
	  bufLimOffset_ += nChars;
	  break;
	}
      }
    }
    else
      so_ = 0;
  }
  ASSERT(end() < bufLim_);
  if (insertRS_) {
    noteRS();
    insertChar(RS);
    insertRS_ = false;
    bufLimOffset_ += 1;
  }
  switch (recordType_) {
  case unknown:
    {
      const Char *e = findNextCrOrLf(end(), bufLim_);
      if (e) {
	if (*e == '\n') {
	  recordType_ = lf;
	  info_->noteInsertedRSs();
	  *(Char *)e = RE;
	  advanceEnd(e + 1);
	  insertRS_ = true;
	}
	else {
	  if (e + 1 < bufLim_) {
	    if (e[1] == '\n') {
	      recordType_ = crlf;
	      advanceEnd(e + 1);
	      if (e + 2 == bufLim_) {
		bufLim_--;
		bufLimOffset_--;
		insertRS_ = true;
	      }
	    }
	    else {
	      advanceEnd(e + 1);
	      recordType_ = cr;
	      info_->noteInsertedRSs();
	      insertRS_ = true;
	    }
	  }
	  else {
	    recordType_ = crUnknown;
	    advanceEnd(e + 1);
	  }
	}
      }
      else
	advanceEnd(bufLim_);
    }
    break;
  case crUnknown:
    {
      if (*cur() == '\n') {
	noteRS();
	advanceEnd(cur() + 1);
	recordType_ = crlf;
      }
      else {
	advanceEnd(cur() + 1);
	insertRS_ = true;
	recordType_ = cr;
	info_->noteInsertedRSs();
      }
    }
    break;
  case lf:
    {
      Char *e = (Char *)findNextLf(end(), bufLim_);
      if (e) {
	advanceEnd(e + 1);
	*e = RE;
	insertRS_ = true;
      }
      else
	advanceEnd(bufLim_);
    }
    break;
  case cr:
    {
      const Char *e = findNextCr(end(), bufLim_);
      if (e) {
	advanceEnd(e + 1);
	insertRS_ = true;
      }
      else
	advanceEnd(bufLim_);
    }
    break;
  case crlf:
    {
      const Char *e = end();
      for (;;) {
	e = findNextLf(e, bufLim_);
	if (!e) {
	  advanceEnd(bufLim_);
	  break;
	}
	// Need to delete final RS if not followed by anything.
	if (e + 1 == bufLim_) {
	  bufLim_--;
	  bufLimOffset_--;
	  advanceEnd(e);
	  insertRS_ = true;
	  break;
	}
	noteRSAt(e);
	e++;
      }
    }
    break;
  case asis:
    advanceEnd(bufLim_);
    break;
  default:
    CANNOT_HAPPEN();
  }

  return nextChar();
}
Example #24
0
void encode_decode_chunkwise(bool encode, const Codec *codec,
                             const QByteArray &infile_buffer, QFile &outfile)
{
    Encoder *enc = 0;
    Decoder *dec = 0;


    QByteArray indata(inbufsize);
    QByteArray outdata(outbufsize);

    // we're going to need this below:
#define write_full_outdata_then_reset  do { \
     kdDebug( verbose ) << "  flushing output buffer." << endl; \
     if ( writing ) { \
       Q_LONG outlen = outfile.writeBlock( outdata.data(), \
					   outdata.size() ); \
       if ( outlen != (int)outdata.size() ) \
         exit(OUTFILE_WRITE_ERR); \
     } \
     oit = outdata.begin(); \
   } while ( false )

#define report_status(x,y) do { \
     kdDebug( verbose ) << "  " #x "() returned " #y " after processing " \
                        << iit - indata.begin() << " bytes of input.\n" \
			<< "   output iterator now at position " \
			<< oit - outdata.begin() << " of " \
			<< outdata.size() << endl; \
  } while ( false )

#define report_finish_status(y) do { \
     kdDebug( verbose ) << "  finish() returned " #y "\n" \
			<< "   output iterator now at position " \
			<< oit - outdata.begin() << " of " \
			<< outdata.size() << endl; \
  } while ( false )


    // Initialize the output iterators:
    QByteArray::Iterator oit = outdata.begin();
    QByteArray::Iterator oend = outdata.end();

    // Get an encoder. This one you have to delete!
    if(encode)
    {
        enc = codec->makeEncoder(withCRLF);
        assert(enc);
    }
    else
    {
        dec = codec->makeDecoder(withCRLF);
        assert(dec);
    }

    //
    // Loop over input chunks:
    //
    uint offset = 0;
    while(offset < infile_buffer.size())
    {
        uint reallyRead = QMIN(indata.size(), infile_buffer.size() - offset);
        indata.duplicate(infile_buffer.begin() + offset, reallyRead);
        offset += reallyRead;

        kdDebug(verbose) << " read " << reallyRead << " bytes (max: "
                         << indata.size() << ") from input." << endl;

        // setup input iterators:
        QByteArray::ConstIterator iit = indata.begin();
        QByteArray::ConstIterator iend = indata.begin() + reallyRead;

        if(encode)
        {
            //
            // Loop over encode() calls:
            //
            while(!enc->encode(iit, iend, oit, oend))
            {
                report_status(encode, false);
                if(oit == oend)
                    // output buffer full:
                    write_full_outdata_then_reset;
            }
            report_status(encode, true);
        }
        else
        {
            //
            // Loop over decode() calls:
            //
            while(!dec->decode(iit, iend, oit, oend))
            {
                report_status(decode, false);
                if(oit == oend)
                    // output buffer full:
                    write_full_outdata_then_reset;
            }
            report_status(decode, true);
        }
    } // end loop over input chunks

    //
    // Now finish the encoding/decoding:
    // (same loops as above, just s/encode|decode/finish())
    //
    if(withFinish)
        if(encode)
        {
            while(!enc->finish(oit, oend))
            {
                report_finish_status(false);
                if(oit == oend)
                    write_full_outdata_then_reset;
            }
            report_finish_status(true);
        }
        else
        {
            while(!dec->finish(oit, oend))
            {
                report_finish_status(false);
                if(oit == oend)
                    write_full_outdata_then_reset;
            }
            report_finish_status(true);
        }

    //
    // Write out last (partial) output chunk:
    //
    if(writing)
    {
        Q_LONG outlen = outfile.writeBlock(outdata.data(),
                                           oit - outdata.begin());
        if(outlen != oit - outdata.begin())
            exit(OUTFILE_WRITE_ERR);
    }

    //
    // Delete en/decoder:
    //
    if(encode)
        delete enc;
    else
        delete dec;
}
static bool decodeDataObject(Decoder& decoder, RefPtr<DataObjectGtk>& dataObject)
{
    RefPtr<DataObjectGtk> data = DataObjectGtk::create();

    bool hasText;
    if (!decoder.decode(hasText))
        return false;
    if (hasText) {
        String text;
        if (!decoder.decode(text))
            return false;
        data->setText(text);
    }

    bool hasMarkup;
    if (!decoder.decode(hasMarkup))
        return false;
    if (hasMarkup) {
        String markup;
        if (!decoder.decode(markup))
            return false;
        data->setMarkup(markup);
    }

    bool hasURL;
    if (!decoder.decode(hasURL))
        return false;
    if (hasURL) {
        String url;
        if (!decoder.decode(url))
            return false;
        data->setURL(URL(URL(), url), String());
    }

    bool hasURIList;
    if (!decoder.decode(hasURIList))
        return false;
    if (hasURIList) {
        String uriList;
        if (!decoder.decode(uriList))
            return false;
        data->setURIList(uriList);
    }

    bool hasImage;
    if (!decoder.decode(hasImage))
        return false;
    if (hasImage) {
        GRefPtr<GdkPixbuf> image;
        if (!decodeImage(decoder, image))
            return false;
        data->setImage(image.get());
    }

    bool hasUnknownTypeData;
    if (!decoder.decode(hasUnknownTypeData))
        return false;
    if (hasUnknownTypeData) {
        HashMap<String, String> unknownTypes;
        if (!decoder.decode(unknownTypes))
            return false;

        auto end = unknownTypes.end();
        for (auto it = unknownTypes.begin(); it != end; ++it)
            data->setUnknownTypeData(it->key, it->value);
    }

    dataObject = data;

    return true;
}
Example #26
0
void QRcodeReader::decode() {
    Binarizer binarizer(img);
    img = binarizer.getBlackMatrix();

    if (more) {
        imshow("original", rgbImg);
        imshow("test",img);
        waitKey(0);
        printf("**************************************************************\n");
        printf("Begin detection to find the three finder pattern centers:\n");
    }

    Finder finder = Finder(img);
    FinderResult fr = finder.find();
    if (more) {
        printf("\n");
        printf("Three finder pattern centers:\n");
        FinderPoint bL = fr.getBottomLeft();
        FinderPoint tL = fr.getTopLeft();
        FinderPoint tR = fr.getTopRight();
        printf("bottomLeft: (%f, %f)\n", bL.getX(), bL.getY());
        printf("topLeft: (%f, %f)\n", tL.getX(), tL.getY());
        printf("topRight: (%f, %f)\n", tR.getX(), tR.getY());
        Point2f p1 = Point2f(bL.getX(), bL.getY());
        circle(rgbImg, p1, 3, Scalar(0,255,0));
        Point2f p2 = Point2f(tL.getX(), tL.getY());
        circle(rgbImg, p2, 3, Scalar(0,255,0));
        Point2f p3 = Point2f(tR.getX(), tR.getY());
        circle(rgbImg, p3, 3, Scalar(0,255,0));
        imshow("original", rgbImg);
        waitKey(0);
    }

    Detector detector = Detector(img);
    DetectorResult detectorResult = detector.processFinderPatternInfo(fr);
    if (more) {
        vector<FinderPoint> patternPoints = detectorResult.getResultPoints();
        BitMatrix bits = detectorResult.getBits();
        printf("\n");
        printf("Module Size: %f\n", detectorResult.getModuleSize());
        printf("Dimension: %d\n", detectorResult.getDimension());
        printf("Alignment Pattern : (%f, %f)\n", patternPoints[3].getX(), patternPoints[3].getY());
        Point2f p4 = Point2f(patternPoints[3].getX(), patternPoints[3].getY());
        circle(rgbImg, p4, 3, Scalar(0,255,0));
        imshow("original", rgbImg);
        waitKey(0);

        printf("\n");
        printf("The bit matrix:\n");
        bits.display();
        printf("\nDetection Done!\n");
        printf("**************************************************************\n");
        waitKey(0);
    }


    Decoder decoder = Decoder(detectorResult);
    DecoderResult decoderResult = decoder.decode();
    if (more) {
        printf("Decode:\n");
        printf("version : %d\n", decoderResult.getVersion());
        printf("Error correct level : %d\n", decoderResult.getEcLevel());
        vector<char> resultBytes = decoderResult.getResultBytes();
        printf("Data bytes: ");
        for (int i = 0; i < resultBytes.size(); ++i) {
            printf("%d ",resultBytes[i]);
        }
        printf("\n");
        string result = decoderResult.getResultText();
        printf("%s\n", result.c_str());
        waitKey(0);
    }
    else {
        string result = decoderResult.getResultText();
        printf("%s\n", result.c_str());
    }
}
Example #27
0
std:: string SYS2INNER(const std::string &systemString)
{
	return toUTF8String(defaultDecoder.decode(systemString));
}