Skip to content
Snippets Groups Projects
Commit 5c45fab3 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

msgpack: avoid copy during packing

Change-Id: I651cf8f4c8bc08367e90f98a2108cdabf6c53c25
parent b34cd486
No related branches found
No related tags found
No related merge requests found
......@@ -1272,13 +1272,13 @@ IceTransport::packIceMsg(uint8_t version) const
if (not isInitialized())
return {};
std::stringstream ss;
msgpack::sbuffer buffer;
if (version == 1) {
msgpack::pack(ss, version);
msgpack::pack(ss, std::make_pair(pimpl_->local_ufrag_, pimpl_->local_pwd_));
msgpack::pack(ss, static_cast<uint8_t>(pimpl_->component_count_));
msgpack::pack(buffer, version);
msgpack::pack(buffer, std::make_pair(pimpl_->local_ufrag_, pimpl_->local_pwd_));
msgpack::pack(buffer, static_cast<uint8_t>(pimpl_->component_count_));
for (unsigned i = 0; i < pimpl_->component_count_; i++)
msgpack::pack(ss, getLocalCandidates(i));
msgpack::pack(buffer, getLocalCandidates(i));
} else {
SDP sdp;
sdp.ufrag = pimpl_->local_ufrag_;
......@@ -1288,10 +1288,9 @@ IceTransport::packIceMsg(uint8_t version) const
sdp.candidates.reserve(sdp.candidates.size() + candidates.size());
sdp.candidates.insert(sdp.candidates.end(), candidates.begin(), candidates.end());
}
msgpack::pack(ss, sdp);
msgpack::pack(buffer, sdp);
}
auto str(ss.str());
return std::vector<uint8_t>(str.begin(), str.end());
return std::vector<uint8_t>(buffer.data(), buffer.data() + buffer.size());
}
bool
......
......@@ -488,9 +488,9 @@ ConnectionManager::Impl::sendChannelRequest(std::shared_ptr<MultiplexedSocket>&
val.name = channelSock->name();
val.state = ChannelRequestState::REQUEST;
val.channel = channelSock->channel();
std::stringstream ss;
msgpack::pack(ss, val);
auto toSend = ss.str();
msgpack::sbuffer buffer(256);
msgpack::pack(buffer, val);
sock->setOnChannelReady(channelSock->channel(), [channelSock, deviceId, vid, w = weak()]() {
if (auto shared = w.lock()) {
if (auto cb = shared->getPendingCallback({deviceId, vid}))
......@@ -499,8 +499,8 @@ ConnectionManager::Impl::sendChannelRequest(std::shared_ptr<MultiplexedSocket>&
});
std::error_code ec;
int res = sock->write(CONTROL_CHANNEL,
reinterpret_cast<const uint8_t*>(&toSend[0]),
toSend.size(),
reinterpret_cast<const uint8_t*>(buffer.data()),
buffer.size(),
ec);
if (res < 0) {
// TODO check if we should handle errors here
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment