当前位置: 首页>>代码示例>>C++>>正文


C++ Bundle::set方法代码示例

本文整理汇总了C++中Bundle::set方法的典型用法代码示例。如果您正苦于以下问题:C++ Bundle::set方法的具体用法?C++ Bundle::set怎么用?C++ Bundle::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Bundle的用法示例。


在下文中一共展示了Bundle::set方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: toAnyValue

				AnyValue User::toAnyValue() const
				{
					Bundle b = PublicUser::toAnyValue().as<Bundle>();
					b.set("birthdate", _birthday);
					b.set("country", _country);
					b.set("email", _email);
					b.set("product", _product == ProductType::PREMIUM ? "premium" : "free");
					return b;
				}
开发者ID:Thalhammer,项目名称:EasyCpp,代码行数:9,代码来源:User.cpp

示例2:

	TEST(MinistoreSerializer, BuildDocumentStacked)
	{
		Bundle b;
		b.set("hello", "world");
		Bundle b2;
		b2.set("test_value", "1234");
		b.set("obj", b2);
		Serialize::MinistoreSerializer store;
		auto result = store.serialize(b);
		ASSERT_EQ(46, result.size());
		ASSERT_EQ(std::string({ 0x19,0x00,0x00,0x00,0x26, 0x00, 0x05,'w','o','r','l','d',
			0x21, 0x01, 0x0B, 0x00, 0x00, 0x00, 0x26, 0x02, 0x04, '1',
			'2', '3', '4', 'h', 'e', 'l', 'l', 'o', 0x00, 'o', 'b',
			'j', 0x00, 't', 'e', 's', 't', '_', 'v', 'a', 'l', 'u',
			'e', 0x00 }), result);
	}
开发者ID:Thalhammer,项目名称:EasyCpp,代码行数:16,代码来源:MinistoreSerializer.cpp

示例3: toAny

		AnyValue JsonSerializer::toAny(const Json::Value & val)
		{
			std::vector<AnyValue> arr;
			Bundle b;
			switch (val.type())
			{
			case Json::ValueType::arrayValue:
				for (auto e : val) arr.push_back(this->toAny(e));
				return arr;
			case Json::ValueType::booleanValue:
				return val.asBool();
			case Json::ValueType::intValue:
				return (int64_t)val.asInt64();
			case Json::ValueType::nullValue:
				return nullptr;
			case Json::ValueType::objectValue:
				for (Json::ValueConstIterator it = val.begin(); it != val.end(); it++)
				{
					std::string name = it.name();
					b.set(name, this->toAny(*it));
				}
				return b;
			case Json::ValueType::realValue:
				return val.asDouble();
			case Json::ValueType::stringValue:
				return val.asString();
			case Json::ValueType::uintValue:
				return (uint64_t)val.asUInt64();
			}
			return AnyValue();
		}
开发者ID:Thalhammer,项目名称:EasyCpp,代码行数:31,代码来源:JsonSerializer.cpp

示例4: callbackBundleReceived

		void EchoWorker::callbackBundleReceived(const Bundle &b)
		{
			try {
				const PayloadBlock &payload = b.find<PayloadBlock>();

				// generate a echo
				Bundle echo;

				// make a copy of the payload block
				ibrcommon::BLOB::Reference ref = payload.getBLOB();
				echo.push_back(ref);

				// set destination and mark the bundle as singleton destination
				echo.destination = b.source;
				echo.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, true);

				// set the source of the bundle
				echo.source = getWorkerURI();

				// set the lifetime to the same value as the received bundle
				echo.lifetime = b.lifetime;

				// sign the reply if the echo-request was signed too
				if (b.get(dtn::data::PrimaryBlock::DTNSEC_STATUS_VERIFIED))
					echo.set(dtn::data::PrimaryBlock::DTNSEC_REQUEST_SIGN, true);

				// encrypt the reply if the echo-request was encrypt too
				if (b.get(dtn::data::PrimaryBlock::DTNSEC_STATUS_CONFIDENTIAL))
					echo.set(dtn::data::PrimaryBlock::DTNSEC_REQUEST_ENCRYPT, true);

				try {
					const dtn::data::TrackingBlock &tracking = b.find<dtn::data::TrackingBlock>();
					dtn::data::TrackingBlock &target = echo.push_back<dtn::data::TrackingBlock>();

					// copy tracking block
					target = tracking;
				} catch (const dtn::data::Bundle::NoSuchBlockFoundException&) { };

				IBRCOMMON_LOGGER_DEBUG_TAG("EchoWorker", 5) << "echo request received, replying!" << IBRCOMMON_LOGGER_ENDL;

				// send it
				transmit( echo );
			} catch (const dtn::data::Bundle::NoSuchBlockFoundException&) {

			}
		}
开发者ID:SebastianSchildt,项目名称:ibrdtnBLETest,代码行数:46,代码来源:EchoWorker.cpp

示例5: depreciate

Bundle QFirm::depreciate() const {
    const Bundle &a = assets;
    Bundle remaining;
    double left_mult = 1 - depreciation();
    if (left_mult > 0) {
        for (auto g : output()) {
            remaining.set(g.first, a[g.first] * left_mult);
        }
    }
    return remaining;
}
开发者ID:erisproject,项目名称:eris,代码行数:11,代码来源:QFirm.cpp

示例6: createStatusReport

		void StatusReportGenerator::createStatusReport(const dtn::data::MetaBundle &b, StatusReportBlock::TYPE type, StatusReportBlock::REASON_CODE reason)
		{
			// create a new bundle
			Bundle bundle;

			// create a new statusreport block
			StatusReportBlock &report = bundle.push_back<StatusReportBlock>();

			bundle.set(dtn::data::PrimaryBlock::APPDATA_IS_ADMRECORD, true);

			// get the flags and set the status flag
			report._status |= type;

			// set the reason code
			report._reasoncode |= reason;

			switch (type)
			{
				case StatusReportBlock::RECEIPT_OF_BUNDLE:
					report._timeof_receipt.set();
				break;

				case StatusReportBlock::CUSTODY_ACCEPTANCE_OF_BUNDLE:
					report._timeof_custodyaccept.set();
				break;

				case StatusReportBlock::FORWARDING_OF_BUNDLE:
					report._timeof_forwarding.set();
				break;

				case StatusReportBlock::DELIVERY_OF_BUNDLE:
					report._timeof_delivery.set();
				break;

				case StatusReportBlock::DELETION_OF_BUNDLE:
					report._timeof_deletion.set();
				break;

				default:

				break;
			}

			// set source and destination
			bundle._source = dtn::core::BundleCore::local;
			bundle.set(dtn::data::PrimaryBlock::DESTINATION_IS_SINGLETON, true);
			bundle._destination = b.reportto;

			// set bundle parameter
			if (b.get(Bundle::FRAGMENT))
			{
				report._fragment_offset = b.offset;
				report._fragment_length = b.appdatalength;
				report._admfield |= 1;
			}

			report._bundle_timestamp = b.timestamp;
			report._bundle_sequence = b.sequencenumber;
			report._source = b.source;

			dtn::core::BundleGeneratedEvent::raise(bundle);
		}
开发者ID:kleymenus,项目名称:ibrdtn,代码行数:62,代码来源:StatusReportGenerator.cpp

示例7: wrt

		std::vector<uint8_t> BsonSerializer::writeDocument(Bundle& value) const
		{
			std::vector<uint8_t> res;
			BufferWriter wrt(res);

			// Document length
			wrt.writeInt32(0);

			for (auto& elem : value)
			{
				auto info = elem.second.type_info();
				if (info.isArithmetic())
				{
					if (info.isFloatingPoint())
					{
						wrt.writeUInt8(0x01); // double
						wrt.writeCString(elem.first);
						wrt.writeDouble(elem.second.as<double>());
					}
					else {
						wrt.writeUInt8(0x12); // int64
						wrt.writeCString(elem.first);
						wrt.writeInt64(elem.second.as<int64_t>());
					}
				}
				else if (elem.second.isSerializable())
				{
					wrt.writeUInt8(0x03);
					wrt.writeCString(elem.first);
					Bundle v = elem.second.serialize().as<Bundle>();
					auto val = this->writeDocument(v);
					wrt.writeBytes(val.data(), val.size());
				}
				else if (elem.second.isType<std::vector<AnyValue>>())
				{
					wrt.writeUInt8(0x04);
					wrt.writeCString(elem.first);
					std::vector<AnyValue> v = elem.second.as<std::vector<AnyValue>>();
					Bundle b;
					for (size_t i = 0; i < v.size(); i++) b.set(std::to_string(i), v[i]);
					auto val = this->writeDocument(b);
					wrt.writeBytes(val.data(), val.size());
				}
				else if (elem.second.isType<std::vector<uint8_t>>())
				{
					wrt.writeUInt8(0x05);
					wrt.writeCString(elem.first);
					std::vector<uint8_t> v = elem.second.as<std::vector<uint8_t>>();
					if (v.size() > INT32_MAX) throw std::runtime_error("Data too large");
					wrt.writeInt32((int32_t)v.size()); // Binary size
					wrt.writeUInt8(0x00); // Subtype
					wrt.writeBytes(v.data(), v.size()); // Data
				}
				else if (elem.second.isType<bool>())
				{
					wrt.writeUInt8(0x08);
					wrt.writeCString(elem.first);
					bool v = elem.second.as<bool>();
					wrt.writeUInt8(v ? 0x01 : 0x00);
				}
				else if (elem.second.isType<std::nullptr_t>())
				{
					wrt.writeUInt8(0x0A);
					wrt.writeCString(elem.first);
				}
				else if (elem.second.isConvertibleTo<std::string>())
				{
					wrt.writeUInt8(0x02);
					wrt.writeCString(elem.first);
					std::string v = elem.second.as<std::string>();
					if (v.size() > INT32_MAX - 1) throw std::runtime_error("String too large");
					wrt.writeInt32((int32_t)v.size() + 1);
					wrt.writeCString(v);
				}
			}

			wrt.writeUInt8(0x00);

			wrt.setPosition(0);
			wrt.setOverwrite(true);

			// Update Size value
			if (wrt.getSize() > INT32_MAX) throw std::runtime_error("Document to large");
			wrt.writeInt32((int32_t)wrt.getSize());
			return res;
		}
开发者ID:Thalhammer,项目名称:EasyCpp,代码行数:86,代码来源:BsonSerializer.cpp

示例8: deserialize

		AnyValue BsonSerializer::deserialize(const std::string & str)
		{
			Bundle res;
			std::vector<uint8_t> data(str.begin(), str.end());
			BufferReader rdr(data);
			if (rdr.getSize() < 4)
				throw std::invalid_argument("Document must be at least 4 byte long");

			rdr.readInt32();
			while (true)
			{
				uint8_t field_type = rdr.readUInt8();
				if (field_type == 0x00)
					break;

				std::string name = rdr.readCString();

				if (field_type == 0x01)
				{
					res.set(name, rdr.readDouble());
				}
				else if (field_type == 0x02)
				{
					int32_t len = rdr.readInt32();
					res.set(name, rdr.readString(len - 1));
					rdr.readUInt8(); // skip trailing 0
				}
				else if (field_type == 0x03)
				{
					// Document
					int32_t len = rdr.peekInt32();
					const uint8_t* ptr = rdr.readBytes(len);
					std::string document(ptr, ptr + len);
					res.set(name, this->deserialize(document));
				}
				else if (field_type == 0x04)
				{
					// Array
					int32_t len = rdr.peekInt32();
					const uint8_t* ptr = rdr.readBytes(len);
					std::string document(ptr, ptr + len);
					std::vector<AnyValue> bdocres;
					for (auto& elem : this->deserialize(document).as<Bundle>()) bdocres.push_back(elem.second);

					res.set(name, bdocres);
				}
				else if (field_type == 0x05)
				{
					// Binary Data
					int32_t len = rdr.readInt32();
					rdr.readUInt8(); // Subtype
									 // TODO: What to do with subtype ?
					auto ptr = rdr.readBytes(len);
					res.set(name, std::vector<uint8_t>(ptr, ptr + len));
				}
				else if (field_type == 0x06)
				{
					// Deprecated
				}
				else if (field_type == 0x07)
				{
					// ObjectID
					// We don't know what to do with it in standard implementations.
					rdr.readBytes(12);
				}
				else if (field_type == 0x08)
				{
					// Boolean
					res.set(name, (rdr.readUInt8() == 1));
				}
				else if (field_type == 0x09)
				{
					// UTC Date int64
					res.set(name, rdr.readInt64());
				}
				else if (field_type == 0x0A)
				{
					res.set(name, nullptr);
				}
				else if (field_type == 0x0B)
				{
					rdr.readCString();
					rdr.readCString();
				}
				else if (field_type == 0x0C)
				{
					// DB Pointer
					// Deprecated
					int32_t len = rdr.readInt32();
					rdr.readBytes(len + 12);
				}
				else if (field_type == 0x0D)
				{
					// Javascript code
					// Is this a good idea ?
					Bundle js;
					int32_t len = rdr.readInt32();
					js.set("js", rdr.readString(len));
					rdr.readUInt8(); // skip trailing 0
					js.set("scope", Bundle());
//.........这里部分代码省略.........
开发者ID:Thalhammer,项目名称:EasyCpp,代码行数:101,代码来源:BsonSerializer.cpp


注:本文中的Bundle::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。