示例#1
0
uint16 BinaryTree::getU16()
{
    unserialize();
    if(m_pos+2 > m_buffer.size())
        stdext::throw_exception("BinaryTree: getU16 failed");
    uint16 v = stdext::readULE16(&m_buffer[m_pos]);
    m_pos += 2;
    return v;
}
示例#2
0
bool ConcurrentTableSharedStore::get(const String& key, Variant &value) {
  const StoreValue *sval;
  APCHandle *svar = nullptr;
  ConditionalReadLock l(m_lock, !apcExtension::ConcurrentTableLockFree ||
                                m_lockingFlag);
  bool expired = false;
  bool promoteObj = false;
  {
    Map::const_accessor acc;
    if (!m_vars.find(acc, tagStringData(key.get()))) {
      log_apc(std_apc_miss);
      return false;
    } else {
      sval = &acc->second;
      if (sval->expired()) {
        // Because it only has a read lock on the data, deletion from
        // expiration has to happen after the lock is released
        expired = true;
      } else {
        if (!sval->inMem()) {
          std::lock_guard<SmallLock> sval_lock(sval->lock);

          if (!sval->inMem()) {
            svar = unserialize(key, sval);
            if (!svar) return false;
          } else {
            svar = sval->var;
          }
        } else {
          svar = sval->var;
        }

        if (apcExtension::AllowObj && svar->is(KindOfObject) &&
            !svar->getObjAttempted()) {
          // Hold ref here for later promoting the object
          svar->incRef();
          promoteObj = true;
        }
        value = svar->toLocal();
        stats_on_get(key.get(), svar);
      }
    }
  }
  if (expired) {
    log_apc(std_apc_miss);
    eraseImpl(key, true);
    return false;
  }
  log_apc(std_apc_hit);

  if (promoteObj)  {
    handlePromoteObj(key, svar, value);
    // release the extra ref
    svar->decRef();
  }
  return true;
}
示例#3
0
uint32 BinaryTree::getU32()
{
    unserialize();
    if(m_pos+4 > m_buffer.size())
        stdext::throw_exception("BinaryTree: getU32 failed");
    uint32 v = stdext::readULE32(&m_buffer[m_pos]);
    m_pos += 4;
    return v;
}
示例#4
0
uint8 BinaryTree::getU8()
{
    unserialize();
    if(m_pos+1 > m_buffer.size())
        stdext::throw_exception("BinaryTree: getU8 failed");
    uint8 v = m_buffer[m_pos];
    m_pos += 1;
    return v;
}
示例#5
0
void unserialize(const JsonBox::Value & o, std::unordered_set<T> & v)
{
	const JsonBox::Array & a = o.getArray();
	for(u32 i = 0; i < a.size(); ++i)
	{
		T elem;
		unserialize(a[i], elem);
		v.insert(elem);
	}
}
示例#6
0
void unserialize(const JsonBox::Value & o, std::vector<T> & v)
{
	const JsonBox::Array & a = o.getArray();
	v.resize(a.size());
	for(u32 i = 0; i < a.size(); ++i)
	{
		const JsonBox::Value & jv = a[i];
		unserialize(jv, v[i]);
	}
}
示例#7
0
  /*
  ** Unserialize std::string
  */
  inline void			unserialize(std::ifstream &file, std::string & a)
  {
    int				    strSize;
    unserialize(file, strSize);
	char                *str = new char[strSize + 1]();
    file.read(str, strSize);
	str[strSize] = '\0';
	a.assign(str);
	delete[] str;
  }
示例#8
0
  /*
  ** Unserialize std::string
  */
  inline void			unserialize(std::ifstream &file, std::string & a)
  {
    int				strSize;

    unserialize(file, strSize);

    char			buffer[strSize + 1];
    file.read(buffer, strSize);
    buffer[strSize] = '\0';
    a.assign(buffer);
  }
示例#9
0
 //will overflow if more than 128 bytes
 size_t _size()
 {
     char buff[128] = {0};
     size_t buff_n = 0;
     size_t size = 0;
     unserialize(buff, &buff_n, &size);
     size++; // add a byte for the message id
     GS_ASSERT(size > 0 && size < 128);
     //printf("MapMessageToServer: %2d,%2d\n", message_id, size);
     return size;
 }
void gcomm::AsioUdpSocket::read_handler(const asio::error_code& ec,
                                        size_t bytes_transferred)
{
    if (ec)
    {
        //
        return;
    }

    if (bytes_transferred >= NetHeader::serial_size_)
    {
        Critical<AsioProtonet> crit(net_);
        NetHeader hdr;
        try
        {
            unserialize(&recv_buf_[0], NetHeader::serial_size_, 0, hdr);
        }
        catch (gu::Exception& e)
        {
            log_warn << "hdr unserialize failed: " << e.get_errno();
            return;
        }
        if (NetHeader::serial_size_ + hdr.len() != bytes_transferred)
        {
            log_warn << "len " << hdr.len()
                     << " does not match to bytes transferred"
                     << bytes_transferred;
        }
        else
        {
            Datagram dg(
                gu::SharedBuffer(
                    new gu::Buffer(&recv_buf_[0] + NetHeader::serial_size_,
                                   &recv_buf_[0] + NetHeader::serial_size_
                                   + hdr.len())));
            if (net_.checksum_ == true && check_cs(hdr, dg))
            {
                log_warn << "checksum failed, hdr: len=" << hdr.len()
                         << " has_crc32="  << hdr.has_crc32()
                         << " has_crc32c=" << hdr.has_crc32c()
                         << " crc32=" << hdr.crc32();
            }
            else
            {
                net_.dispatch(id(), dg, ProtoUpMeta());
            }
        }
    }
    else
    {
        log_warn << "short read of " << bytes_transferred;
    }
    async_receive();
}
示例#11
0
bool SoftUpdatePrefsXMLSerializer::unserialize( const std::string& xml )
{
	TiXmlDocument doc;

	doc.Parse(xml.c_str());

	TiXmlHandle docHandle(&doc);
	TiXmlNode*  node = docHandle.FirstChild("softUpdate").Node();

	return unserialize( node );
}
示例#12
0
void mapbuffer::load(std::string worldname)
{
 std::ifstream fin;
 std::stringstream worldmap;
 worldmap << world_generator->all_worlds[worldname]->world_path << "/maps.txt";

 fin.open(worldmap.str().c_str());
 if (!fin.is_open())
  return;
 unserialize(fin);
 fin.close();
}
示例#13
0
文件: model.cpp 项目: fizx/mongo
    bool Model::load(BSONObj& query){
        ScopedDbConnection conn( modelServer() );

        BSONObj b = conn->findOne(getNS(), query);
        conn.done();
        
        if ( b.isEmpty() )
            return false;
        
        unserialize(b);
        _id = b["_id"].wrap().getOwned();
        return true;
    }
示例#14
0
文件: Net.cpp 项目: Zl0bin/493final
 int Split_UDP_Socket::receive(IPaddress &ip, const void * const &data, const Uint16 &num_bytes) {
   for(int retval = -1; retval;) {
     std::string s;
     s.resize(m_chunk_size);
     
     retval = UDP_Socket::receive(ip, s);
     if(retval) {
       Nonce nonce;
       Uint16 num_chunks;
       Uint16 which;
       Chunk chunk;
       
       {
         std::istringstream is(s);
         unserialize(unserialize(nonce.unserialize(is), num_chunks), which);
         
         const Uint16 offset = static_cast<Uint16>(nonce.size()) + 2u * sizeof(Uint16);
         
         chunk.size = s.size() - offset;
         chunk.data = new char [chunk.size];
         memcpy(chunk.data, s.c_str() + offset, chunk.size);
       }
       
       const Chunk_Set * cs = m_chunk_collector.add_chunk(ip, nonce, num_chunks, which, chunk);
       if(!cs)
         continue;
       
       Chunk packet = cs->receive();
       if(num_bytes >= Uint16(packet.size)) {
         memcpy(const_cast<void *>(data), packet.data, packet.size);
         return int(packet.size);
       }
       
       return 0;
     }
   }
   
   return 0;
 }
示例#15
0
std::string BinaryTree::getString(uint16 len)
{
    unserialize();
    if(len == 0)
        len = getU16();

    if(m_pos+len > m_buffer.size())
        stdext::throw_exception("BinaryTree: getString failed: string length exceeded buffer size.");

    std::string ret((char *)&m_buffer[m_pos], len);
    m_pos += len;
    return ret;
}
示例#16
0
void mapbuffer::load()
{
 if (!master_game) {
  debugmsg("Can't load mapbuffer without a master_game");
  return;
 }
 std::ifstream fin;
 fin.open("save/maps.txt");
 if (!fin.is_open())
  return;
 unserialize(fin);
 fin.close();
}
示例#17
0
文件: core.cpp 项目: FerryT/OGO-2.3
bool Object::unserialize(const string &str)
{
	vector<string> arg;
	size_t left, right;
	for (left = 0, right = str.find("|", 0); right != string::npos;
	right = str.find("|", right))
	{
		arg.push_back(str.substr(left, right - left));
		left = ++right;
	}
	arg.push_back(str.substr(left));
	return unserialize(arg);
}
示例#18
0
static void unserializeProp(VariableUnserializer *uns,
                            ObjectData *obj, const String& key,
                            Class* ctx, const String& realKey,
                            int nProp) {
  // Do a two-step look up
  bool visible, accessible, unset;
  auto t = &tvAsVariant(obj->getProp(ctx, key.get(),
                                     visible, accessible, unset));
  assert(!unset);
  if (!t || !accessible) {
    // Dynamic property. If this is the first, and we're using MixedArray,
    // we need to pre-allocate space in the array to ensure the elements
    // dont move during unserialization.
    //
    // TODO(#2881866): this assumption means we can't do reallocations
    // when promoting kPackedKind -> kMixedKind.
    t = &obj->reserveProperties(nProp).lvalAt(realKey, AccessFlags::Key);
  }

  t->unserialize(uns);

  if (!RuntimeOption::EvalCheckRepoAuthDeserialize) return;
  if (!RuntimeOption::RepoAuthoritative) return;
  if (!Repo::get().global().HardPrivatePropInference) return;

  /*
   * We assume for performance reasons in repo authoriative mode that
   * we can see all the sets to private properties in a class.
   *
   * It's a hole in this if we don't check unserialization doesn't
   * violate what we've seen, which we handle by throwing if the repo
   * was built with this option.
   */
  auto const cls  = obj->getVMClass();
  auto const slot = cls->lookupDeclProp(key.get());
  if (UNLIKELY(slot == kInvalidSlot)) return;
  auto const repoTy = obj->getVMClass()->declPropRepoAuthType(slot);
  if (LIKELY(tvMatchesRepoAuthType(*t->asTypedValue(), repoTy))) {
    return;
  }

  auto msg = folly::format(
    "Property {} for class {} was deserialized with type ({}) that "
    "didn't match what we inferred in static analysis",
    key.data(),
    obj->getVMClass()->name()->data(),
    tname(t->asTypedValue()->m_type)
  ).str();
  throw Exception(msg);
}
示例#19
0
  IArchive& operator&(std::vector<T>& value)
  {
    int length;

    if (str[offset] == 'a' && str[offset + 1] == typecode<T>())
      offset += 2;
    else
      throw_unmatching_types();
    unserialize_number<int>(length);
    value.resize(length);
    for (int i = 0 ; i < length ; ++i)
      unserialize(value[i]);
    return *this;
  }
const KeyIn&
galera::KeySetIn::get_key() const
{
    size_t offset(0);
    while (offset < keys_.size())
    {
        KeyOS key(version_);
        if ((offset = unserialize(&keys_[0], keys_.size(), offset, key)) == 0)
        {
            gu_throw_fatal << "failed to unserialize key";
        }
        s.push_back(key);
    }
    assert(offset == keys_.size());
}
示例#21
0
galera::GcsActionTrx::GcsActionTrx(const struct gcs_action& act)
    :
    trx_(new TrxHandle())
{
    assert(act.seqno_l != GCS_SEQNO_ILL);
    assert(act.seqno_g != GCS_SEQNO_ILL);

    const gu::byte_t* const buf = reinterpret_cast<const gu::byte_t*>(act.buf);

    size_t offset(unserialize(buf, act.size, 0, *trx_));

    // trx_->append_write_set(buf + offset, act.size - offset);
    trx_->set_write_set_buffer(buf + offset, act.size - offset);
    trx_->set_received(act.buf, act.seqno_l, act.seqno_g);
    trx_->lock();
}
示例#22
0
bool History::load(const std::string & url) {
	FileReader file(url);

	if (file.open()) {
		std::string data = file.read();

		//clear & unserialize the history
		clear(HistoryMemento::Any, false);
		bool toReturn = unserialize(data);
		historyLoadedEvent(*this);

		return toReturn;
	}

	return true;
}
示例#23
0
KviKvsVariant * KviKvsVariant::unserialize(const QString & szBuffer)
{
	KviKvsVariant * pResult = NULL;

	const QChar * pAux = (const QChar *)szBuffer.constData();

	pResult = unserialize(&pAux);

	if(pAux->unicode())
	{
		//strange extra characters?
		if(pResult)
			delete pResult;
		pResult = NULL;
	}

	return pResult;
}
示例#24
0
文件: apc_cache.c 项目: Cum6upck/apcu
/* {{{ my_unserialize_object */
static zval* my_unserialize_object(zval* dst, const zval* src, apc_context_t* ctxt)
{
    apc_unserialize_t unserialize = APC_UNSERIALIZER_NAME(php);
    void *config = NULL;

    if(ctxt->serializer) {
        unserialize = ctxt->serializer->unserialize;
        config = (ctxt->serializer->config != NULL) ? ctxt->serializer->config : ctxt;
    }

    if(unserialize(dst, (unsigned char *)Z_STRVAL_P(src), Z_STRLEN_P(src), config)) {
        return dst;
    } else {
        zval_dtor(dst);
        ZVAL_NULL(dst);
    }
    return dst;
}
示例#25
0
static mrpc_status_t unformat_message(xdrproc_t type, unsigned size,
			struct mrpc_message *msg, void **result)
{
	void *buf;
	mrpc_status_t ret;

	if (size && result == NULL)
		return MINIRPC_ENCODING_ERR;
	buf=mrpc_alloc_argument(size);
	ret=unserialize(type, msg->data, msg->hdr.datalen, buf, size);
	if (ret) {
		mrpc_free_argument(NULL, buf);
		return ret;
	}
	if (result != NULL)
		*result=buf;
	return MINIRPC_OK;
}
示例#26
0
void cache::unserialize(const core::coll_helper &_coll)
{
	core::iarray* sets = _coll.get_value_as_array("sets");
	if (!sets)
		return;

	sets_.reserve(sets->size());

	for (int32_t i = 0; i < sets->size(); i++)
	{
		core::coll_helper coll_set(sets->get_at(i)->get_as_collection(), false);

		auto inserted_set = std::make_shared<set>();

		inserted_set->unserialize(coll_set);

		sets_.push_back(inserted_set);
	}
}
示例#27
0
void
subscribe_action_t::data_event(int rc, std::string value, const zookeeper::node_stat& stat) {
    if(rc == ZNONODE) {
        if(last_version != min_version && last_version != not_existing_version) {
            auto code = cocaine::error::make_error_code(static_cast<cocaine::error::zookeeper_errors>(rc));
            result->abort(code);
        } else {
            // Write that node is not exist to client only first time.
            // After that set a watch to see when it will appear
            if(last_version == min_version) {
                std::lock_guard<std::mutex> guard(write_lock);
                if (not_existing_version > last_version) {
                    result->write(versioned_value_t(value_t(), not_existing_version));
                }
            }
            try {
                ctx.zk.exists(path, *this, *this);
            } catch(const std::system_error& e) {
                COCAINE_LOG_WARNING(ctx.log, "failure during subscription(get): {}", e.what());
                result->abort(e.code());
            }
        }
    } else if (rc != 0) {
        auto code = cocaine::error::make_error_code(static_cast<cocaine::error::zookeeper_errors>(rc));
        result->abort(code);
    } else if (stat.numChildren != 0) {
        result->abort(cocaine::error::child_not_allowed);
    } else {
        version_t new_version(stat.version);
        std::lock_guard<std::mutex> guard(write_lock);
        if (new_version > last_version) {
            last_version = new_version;
            value_t val;
            try {
                result->write(versioned_value_t(unserialize(value), new_version));
            } catch(const std::system_error& e) {
                result->abort(e.code());
            }
        }
    }
}
示例#28
0
KviKvsVariant * KviKvsVariant::unserializeArray(const QChar ** ppAux)
{
	KviKvsArray * pArray = new KviKvsArray();
	KviKvsVariant * pElement = 0;
	(*ppAux)++;
	int i=0;
	while(1)
	{
		pElement = unserialize(ppAux);
		if(pElement)
		{
			pArray->set(i,pElement);
			i++;
			while((*ppAux)->isSpace())
				(*ppAux)++;
			switch((*ppAux)->unicode())
			{
				case ',':
					//goto next
					(*ppAux)++;
				break;
				case ']':
					//EOF array
					(*ppAux)++;
					return new KviKvsVariant(pArray);
				break;
				default:
					delete pArray;
					return 0;
				break;
			}
		} else {
			//error
			delete pArray;
			return 0;
		}
	}
	return 0;
}
示例#29
0
/// <summary>
/// Completely resets the mixer. This must be called whenever an audio input
/// or the output format changes in a way that cannot be done on-the-fly.
/// WARNING: This causes an output discontinuity which means that it cannot be
/// called while broadcasting!
/// </summary>
void AudioMixer::resetMixer()
{
	// Serialize to a temporary buffer
	QByteArray data;
	QBuffer buffer(&data);
	buffer.open(QIODevice::ReadWrite);
	{
		QDataStream stream(&buffer);
		stream.setByteOrder(QDataStream::LittleEndian);
		stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
		stream.setVersion(12);
		serialize(&stream);
		if(stream.status() != QDataStream::Ok) {
			// TODO
		}
	}

	// Completely reset mixer
	while(!m_inputs.isEmpty())
		destroyInput(m_inputs.first());
	m_outStats = AudioStats(getSampleRate(), getNumChannels());
	m_refTimestampUsec = App->getUsecSinceFrameOrigin();
	m_minInputDelayUsec = 0;
	m_sampleNum = 0;

	// Restore previous state
	buffer.seek(0);
	{
		QDataStream stream(&buffer);
		stream.setByteOrder(QDataStream::LittleEndian);
		stream.setFloatingPointPrecision(QDataStream::SinglePrecision);
		stream.setVersion(12);
		unserialize(&stream);
		if(stream.status() != QDataStream::Ok) {
			// TODO
		}
	}
}
示例#30
0
// Load the variable from EEPROM, if supported
//
bool AP_Var::load(void)
{
    uint8_t vbuf[k_size_max];
    size_t size;

    // if the variable is a group member, load the group
    if (_group) {
        return _group->load();
    }

    debug("load: %S", _name ? _name : PSTR("??"));

    // locate the variable in EEPROM, but do not allocate space
    if (!_EEPROM_locate(false)) {
        debug("locate failed");
        return false;
    }

    // ask the serializer how big the variable is
    //
    // XXX should check size in EEPROM var header too...
    //
    size = serialize(NULL, 0);
    if (0 == size) {
        debug("cannot load (too big or not supported)");
        return false;
    }

    // Read the buffer from EEPROM, now that _EEPROM_locate
    // has converted _key into an EEPROM address.
    //
    if (size <= sizeof(vbuf)) {
        debug("loading %u from %u", size, _key);
        eeprom_read_block(vbuf, (void *)_key, size);
        return unserialize(vbuf, size);
    }
    return false;
}