Index: webrtc/api/sctputils.cc |
diff --git a/webrtc/api/sctputils.cc b/webrtc/api/sctputils.cc |
index f2d1b0f54af921d79f6bebbef238efde76a2684b..1a2c282ff68103f5ecd16e6cdb6d1be5a3234614 100644 |
--- a/webrtc/api/sctputils.cc |
+++ b/webrtc/api/sctputils.cc |
@@ -10,8 +10,8 @@ |
#include "webrtc/api/sctputils.h" |
+#include "webrtc/base/buffer.h" |
#include "webrtc/base/bytebuffer.h" |
-#include "webrtc/base/copyonwritebuffer.h" |
#include "webrtc/base/logging.h" |
namespace webrtc { |
@@ -31,27 +31,26 @@ |
DCOMCT_UNORDERED_PARTIAL_TIME = 0x82, |
}; |
-bool IsOpenMessage(const rtc::CopyOnWriteBuffer& payload) { |
+bool IsOpenMessage(const rtc::Buffer& payload) { |
// Format defined at |
// http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 |
- if (payload.size() < 1) { |
+ |
+ rtc::ByteBuffer buffer(payload); |
+ uint8_t message_type; |
+ if (!buffer.ReadUInt8(&message_type)) { |
LOG(LS_WARNING) << "Could not read OPEN message type."; |
return false; |
} |
- |
- uint8_t message_type = payload[0]; |
return message_type == DATA_CHANNEL_OPEN_MESSAGE_TYPE; |
} |
-bool ParseDataChannelOpenMessage(const rtc::CopyOnWriteBuffer& payload, |
+bool ParseDataChannelOpenMessage(const rtc::Buffer& payload, |
std::string* label, |
DataChannelInit* config) { |
// Format defined at |
// http://tools.ietf.org/html/draft-jesup-rtcweb-data-protocol-04 |
- // TODO(jbauch): avoid copying the payload data into the ByteBuffer, see |
- // https://bugs.chromium.org/p/webrtc/issues/detail?id=5670 |
- rtc::ByteBuffer buffer(payload.data<char>(), payload.size()); |
+ rtc::ByteBuffer buffer(payload); |
uint8_t message_type; |
if (!buffer.ReadUInt8(&message_type)) { |
LOG(LS_WARNING) << "Could not read OPEN message type."; |
@@ -121,13 +120,13 @@ |
return true; |
} |
-bool ParseDataChannelOpenAckMessage(const rtc::CopyOnWriteBuffer& payload) { |
- if (payload.size() < 1) { |
+bool ParseDataChannelOpenAckMessage(const rtc::Buffer& payload) { |
+ rtc::ByteBuffer buffer(payload); |
+ uint8_t message_type; |
+ if (!buffer.ReadUInt8(&message_type)) { |
LOG(LS_WARNING) << "Could not read OPEN_ACK message type."; |
return false; |
} |
- |
- uint8_t message_type = payload[0]; |
if (message_type != DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE) { |
LOG(LS_WARNING) << "Data Channel OPEN_ACK message of unexpected type: " |
<< message_type; |
@@ -138,7 +137,7 @@ |
bool WriteDataChannelOpenMessage(const std::string& label, |
const DataChannelInit& config, |
- rtc::CopyOnWriteBuffer* payload) { |
+ rtc::Buffer* payload) { |
// Format defined at |
// http://tools.ietf.org/html/draft-ietf-rtcweb-data-protocol-00#section-6.1 |
uint8_t channel_type = 0; |
@@ -169,7 +168,6 @@ |
rtc::ByteBuffer buffer( |
NULL, 20 + label.length() + config.protocol.length(), |
rtc::ByteBuffer::ORDER_NETWORK); |
- // TODO(tommi): Add error handling and check resulting length. |
buffer.WriteUInt8(DATA_CHANNEL_OPEN_MESSAGE_TYPE); |
buffer.WriteUInt8(channel_type); |
buffer.WriteUInt16(priority); |
@@ -182,9 +180,9 @@ |
return true; |
} |
-void WriteDataChannelOpenAckMessage(rtc::CopyOnWriteBuffer* payload) { |
- uint8_t data = DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE; |
- payload->SetData(&data, sizeof(data)); |
+void WriteDataChannelOpenAckMessage(rtc::Buffer* payload) { |
+ rtc::ByteBuffer buffer(rtc::ByteBuffer::ORDER_NETWORK); |
+ buffer.WriteUInt8(DATA_CHANNEL_OPEN_ACK_MESSAGE_TYPE); |
+ payload->SetData(buffer.Data(), buffer.Length()); |
} |
- |
} // namespace webrtc |