Beispiel #1
0
static inline void writePairString(rapid::IoBuffer* buffer, std::string const &name, std::string const &value) {
	if (!name.empty()) {
		encodeInteger(buffer, 7, static_cast<uint32_t>(name.length()));
		rapid::writeData<rapid::utils::NoEndian>(buffer, reinterpret_cast<uint8_t const*>(name.c_str()), name.length());
	}
	if (!value.empty()) {
		encodeInteger(buffer, 7, static_cast<uint32_t>(value.length()));
		rapid::writeData<rapid::utils::NoEndian>(buffer, reinterpret_cast<uint8_t const*>(value.c_str()), value.length());
	}
}
Beispiel #2
0
void Http2Hpack::encodeHeader(rapid::IoBuffer* buffer, std::string const &name, std::string const &value) {
	uint8_t index = 0;

	auto ret = s_staticIndexTable.lookup(name, value, index);
	if (ret == StaticIndexTable::LOOKUP_RESULT_NOT_EXSIT) {
		// Literal Header Field without Indexing — New Name
		rapid::writeData(buffer, static_cast<uint8_t>(0x00));
		writePairString(buffer, name, value);
		RAPID_LOG_TRACE() << "Indexing — New Name: " << name;
		return;
	}
	
	auto &entry = s_staticIndexTable.getEntry(index);
	if (isNeverIndexing(entry)) {
		// Literal Header Field Never Indexed — Indexed Name
		rapid::writeData(buffer, static_cast<uint8_t>(0x10));
		writePairString(buffer, entry.name_, value);
		RAPID_LOG_TRACE() << "Never Indexed — Indexed Name: " << entry.name_;
		return;
	}

	if (isWithoutIndexing(entry)) {
		// Literal Header Field without Indexing — New Name
		rapid::writeData(buffer, static_cast<uint8_t>(0x00));
		writePairString(buffer, entry.name_, value);
		RAPID_LOG_TRACE() << "Without Indexed — Indexed Name: " << entry.name_;
		return;
	}

	auto pData = buffer->writeData();
	if (ret == StaticIndexTable::LOOKUP_RESULT_FIND_NAME_AND_VALUE) {
		// Indexed Header Field Representation			
		encodeInteger(buffer, 7, index);
		*pData |= 0x80;
		RAPID_LOG_TRACE() << "Representation: " << name;
	} else {
		// Literal Header Field with Incremental Indexing — Indexed Name
		encodeInteger(buffer, 6, index);
		*pData |= 0x40;
		writePairString(buffer, "", value);
		RAPID_LOG_TRACE() << "Incremental Indexing — Indexed Name: " << rapid::utils::toLower(entry.name_);
	}
}
Beispiel #3
0
void BinaryEncoder::encodeString(std::vector<uint8_t>& encodedData, std::string& string)
{
	try
	{
		encodeInteger(encodedData, string.size());
		if(string.size() > 0) encodedData.insert(encodedData.end(), string.begin(), string.end());
	}
	catch(const std::exception& ex)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(const Exception& ex)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__, ex.what());
    }
    catch(...)
    {
    	_bl->out.printEx(__FILE__, __LINE__, __PRETTY_FUNCTION__);
    }
}
void ShortRange::encode(buffer* b)
{
    ENCODE_PREAMBLE
	SpinOperation::encode(b);
    char version = 0;
    encodeChar(version, b);
	
    encodeInteger(pbc[0], b);
    encodeInteger(pbc[1], b);
    encodeInteger(pbc[2], b);
	
    encodeInteger(num, b);
	
    for(int i=0; i<num; i++)
    {
	encodeInteger(pathways[i].fromsite, b);
	encodeInteger(pathways[i].tosite, b);
	encodeDouble(pathways[i].strength, b);
	for(int j=0; j<9; j++)
	    encodeDouble(pathways[i].matrix[j], b);
	encodeDouble(pathways[i].sig_dot_sig_pow, b);
		    
    }
}