mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
In rtc::ByteBuffer drop support for ORDER_HOST as unused
Bug: None Change-Id: Ideab428b13d981cddf9784cfd07fb7dfb2e914fe Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/159698 Reviewed-by: Karl Wiberg <kwiberg@webrtc.org> Commit-Queue: Danil Chapovalov <danilchap@webrtc.org> Cr-Commit-Position: refs/heads/master@{#29803}
This commit is contained in:
parent
74f35e48d5
commit
7b46e17c31
7 changed files with 163 additions and 233 deletions
|
@ -1190,7 +1190,7 @@ void PseudoTcp::disableWindowScale() {
|
|||
}
|
||||
|
||||
void PseudoTcp::queueConnectMessage() {
|
||||
rtc::ByteBufferWriter buf(rtc::ByteBuffer::ORDER_NETWORK);
|
||||
rtc::ByteBufferWriter buf;
|
||||
|
||||
buf.WriteUInt8(CTL_CONNECT);
|
||||
if (m_support_wnd_scale) {
|
||||
|
|
|
@ -31,8 +31,7 @@ uint32_t ReduceTransactionId(const std::string& transaction_id) {
|
|||
RTC_DCHECK(transaction_id.length() == cricket::kStunTransactionIdLength ||
|
||||
transaction_id.length() ==
|
||||
cricket::kStunLegacyTransactionIdLength);
|
||||
ByteBufferReader reader(transaction_id.c_str(), transaction_id.length(),
|
||||
rtc::ByteBuffer::ORDER_NETWORK);
|
||||
ByteBufferReader reader(transaction_id.c_str(), transaction_id.length());
|
||||
uint32_t result = 0;
|
||||
uint32_t next;
|
||||
while (reader.ReadUInt32(&next)) {
|
||||
|
|
|
@ -169,8 +169,7 @@ bool WriteDataChannelOpenMessage(const std::string& label,
|
|||
}
|
||||
|
||||
rtc::ByteBufferWriter buffer(NULL,
|
||||
20 + label.length() + config.protocol.length(),
|
||||
rtc::ByteBuffer::ORDER_NETWORK);
|
||||
20 + label.length() + config.protocol.length());
|
||||
// TODO(tommi): Add error handling and check resulting length.
|
||||
buffer.WriteUInt8(DATA_CHANNEL_OPEN_MESSAGE_TYPE);
|
||||
buffer.WriteUInt8(channel_type);
|
||||
|
|
|
@ -16,41 +16,22 @@ namespace rtc {
|
|||
|
||||
ByteBufferWriter::ByteBufferWriter() : ByteBufferWriterT() {}
|
||||
|
||||
ByteBufferWriter::ByteBufferWriter(ByteOrder byte_order)
|
||||
: ByteBufferWriterT(byte_order) {}
|
||||
|
||||
ByteBufferWriter::ByteBufferWriter(const char* bytes, size_t len)
|
||||
: ByteBufferWriterT(bytes, len) {}
|
||||
|
||||
ByteBufferWriter::ByteBufferWriter(const char* bytes,
|
||||
size_t len,
|
||||
ByteOrder byte_order)
|
||||
: ByteBufferWriterT(bytes, len, byte_order) {}
|
||||
|
||||
ByteBufferReader::ByteBufferReader(const char* bytes, size_t len)
|
||||
: ByteBuffer(ORDER_NETWORK) {
|
||||
ByteBufferReader::ByteBufferReader(const char* bytes, size_t len) {
|
||||
Construct(bytes, len);
|
||||
}
|
||||
|
||||
ByteBufferReader::ByteBufferReader(const char* bytes,
|
||||
size_t len,
|
||||
ByteOrder byte_order)
|
||||
: ByteBuffer(byte_order) {
|
||||
Construct(bytes, len);
|
||||
}
|
||||
|
||||
ByteBufferReader::ByteBufferReader(const char* bytes)
|
||||
: ByteBuffer(ORDER_NETWORK) {
|
||||
ByteBufferReader::ByteBufferReader(const char* bytes) {
|
||||
Construct(bytes, strlen(bytes));
|
||||
}
|
||||
|
||||
ByteBufferReader::ByteBufferReader(const Buffer& buf)
|
||||
: ByteBuffer(ORDER_NETWORK) {
|
||||
ByteBufferReader::ByteBufferReader(const Buffer& buf) {
|
||||
Construct(buf.data<char>(), buf.size());
|
||||
}
|
||||
|
||||
ByteBufferReader::ByteBufferReader(const ByteBufferWriter& buf)
|
||||
: ByteBuffer(buf.Order()) {
|
||||
ByteBufferReader::ByteBufferReader(const ByteBufferWriter& buf) {
|
||||
Construct(buf.Data(), buf.Length());
|
||||
}
|
||||
|
||||
|
@ -76,7 +57,7 @@ bool ByteBufferReader::ReadUInt16(uint16_t* val) {
|
|||
if (!ReadBytes(reinterpret_cast<char*>(&v), 2)) {
|
||||
return false;
|
||||
} else {
|
||||
*val = (Order() == ORDER_NETWORK) ? NetworkToHost16(v) : v;
|
||||
*val = NetworkToHost16(v);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -87,14 +68,12 @@ bool ByteBufferReader::ReadUInt24(uint32_t* val) {
|
|||
|
||||
uint32_t v = 0;
|
||||
char* read_into = reinterpret_cast<char*>(&v);
|
||||
if (Order() == ORDER_NETWORK || IsHostBigEndian()) {
|
||||
++read_into;
|
||||
}
|
||||
|
||||
if (!ReadBytes(read_into, 3)) {
|
||||
return false;
|
||||
} else {
|
||||
*val = (Order() == ORDER_NETWORK) ? NetworkToHost32(v) : v;
|
||||
*val = NetworkToHost32(v);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -107,7 +86,7 @@ bool ByteBufferReader::ReadUInt32(uint32_t* val) {
|
|||
if (!ReadBytes(reinterpret_cast<char*>(&v), 4)) {
|
||||
return false;
|
||||
} else {
|
||||
*val = (Order() == ORDER_NETWORK) ? NetworkToHost32(v) : v;
|
||||
*val = NetworkToHost32(v);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +99,7 @@ bool ByteBufferReader::ReadUInt64(uint64_t* val) {
|
|||
if (!ReadBytes(reinterpret_cast<char*>(&v), 8)) {
|
||||
return false;
|
||||
} else {
|
||||
*val = (Order() == ORDER_NETWORK) ? NetworkToHost64(v) : v;
|
||||
*val = NetworkToHost64(v);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,42 +20,14 @@
|
|||
#include "rtc_base/byte_order.h"
|
||||
#include "rtc_base/constructor_magic.h"
|
||||
|
||||
// Reads/Writes from/to buffer using network byte order (big endian)
|
||||
namespace rtc {
|
||||
|
||||
class ByteBuffer {
|
||||
public:
|
||||
enum ByteOrder {
|
||||
ORDER_NETWORK = 0, // Default, use network byte order (big endian).
|
||||
ORDER_HOST, // Use the native order of the host.
|
||||
};
|
||||
|
||||
explicit ByteBuffer(ByteOrder byte_order) : byte_order_(byte_order) {}
|
||||
|
||||
ByteOrder Order() const { return byte_order_; }
|
||||
|
||||
private:
|
||||
ByteOrder byte_order_;
|
||||
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(ByteBuffer);
|
||||
};
|
||||
|
||||
template <class BufferClassT>
|
||||
class ByteBufferWriterT : public ByteBuffer {
|
||||
class ByteBufferWriterT {
|
||||
public:
|
||||
// |byte_order| defines order of bytes in the buffer.
|
||||
ByteBufferWriterT() : ByteBuffer(ORDER_NETWORK) {
|
||||
Construct(nullptr, kDefaultCapacity);
|
||||
}
|
||||
explicit ByteBufferWriterT(ByteOrder byte_order) : ByteBuffer(byte_order) {
|
||||
Construct(nullptr, kDefaultCapacity);
|
||||
}
|
||||
ByteBufferWriterT(const char* bytes, size_t len) : ByteBuffer(ORDER_NETWORK) {
|
||||
Construct(bytes, len);
|
||||
}
|
||||
ByteBufferWriterT(const char* bytes, size_t len, ByteOrder byte_order)
|
||||
: ByteBuffer(byte_order) {
|
||||
Construct(bytes, len);
|
||||
}
|
||||
ByteBufferWriterT() { Construct(nullptr, kDefaultCapacity); }
|
||||
ByteBufferWriterT(const char* bytes, size_t len) { Construct(bytes, len); }
|
||||
|
||||
const char* Data() const { return buffer_.data(); }
|
||||
size_t Length() const { return buffer_.size(); }
|
||||
|
@ -67,23 +39,21 @@ class ByteBufferWriterT : public ByteBuffer {
|
|||
WriteBytes(reinterpret_cast<const char*>(&val), 1);
|
||||
}
|
||||
void WriteUInt16(uint16_t val) {
|
||||
uint16_t v = (Order() == ORDER_NETWORK) ? HostToNetwork16(val) : val;
|
||||
uint16_t v = HostToNetwork16(val);
|
||||
WriteBytes(reinterpret_cast<const char*>(&v), 2);
|
||||
}
|
||||
void WriteUInt24(uint32_t val) {
|
||||
uint32_t v = (Order() == ORDER_NETWORK) ? HostToNetwork32(val) : val;
|
||||
uint32_t v = HostToNetwork32(val);
|
||||
char* start = reinterpret_cast<char*>(&v);
|
||||
if (Order() == ORDER_NETWORK || IsHostBigEndian()) {
|
||||
++start;
|
||||
}
|
||||
WriteBytes(start, 3);
|
||||
}
|
||||
void WriteUInt32(uint32_t val) {
|
||||
uint32_t v = (Order() == ORDER_NETWORK) ? HostToNetwork32(val) : val;
|
||||
uint32_t v = HostToNetwork32(val);
|
||||
WriteBytes(reinterpret_cast<const char*>(&v), 4);
|
||||
}
|
||||
void WriteUInt64(uint64_t val) {
|
||||
uint64_t v = (Order() == ORDER_NETWORK) ? HostToNetwork64(val) : val;
|
||||
uint64_t v = HostToNetwork64(val);
|
||||
WriteBytes(reinterpret_cast<const char*>(&v), 8);
|
||||
}
|
||||
// Serializes an unsigned varint in the format described by
|
||||
|
@ -139,11 +109,8 @@ class ByteBufferWriterT : public ByteBuffer {
|
|||
|
||||
class ByteBufferWriter : public ByteBufferWriterT<BufferT<char>> {
|
||||
public:
|
||||
// |byte_order| defines order of bytes in the buffer.
|
||||
ByteBufferWriter();
|
||||
explicit ByteBufferWriter(ByteOrder byte_order);
|
||||
ByteBufferWriter(const char* bytes, size_t len);
|
||||
ByteBufferWriter(const char* bytes, size_t len, ByteOrder byte_order);
|
||||
|
||||
private:
|
||||
RTC_DISALLOW_COPY_AND_ASSIGN(ByteBufferWriter);
|
||||
|
@ -151,10 +118,9 @@ class ByteBufferWriter : public ByteBufferWriterT<BufferT<char>> {
|
|||
|
||||
// The ByteBufferReader references the passed data, i.e. the pointer must be
|
||||
// valid during the lifetime of the reader.
|
||||
class ByteBufferReader : public ByteBuffer {
|
||||
class ByteBufferReader {
|
||||
public:
|
||||
ByteBufferReader(const char* bytes, size_t len);
|
||||
ByteBufferReader(const char* bytes, size_t len, ByteOrder byte_order);
|
||||
|
||||
// Initializes buffer from a zero-terminated string.
|
||||
explicit ByteBufferReader(const char* bytes);
|
||||
|
|
|
@ -82,20 +82,15 @@ TEST(ByteBufferTest, TestBufferLength) {
|
|||
}
|
||||
|
||||
TEST(ByteBufferTest, TestReadWriteBuffer) {
|
||||
ByteBufferWriter::ByteOrder orders[2] = {ByteBufferWriter::ORDER_HOST,
|
||||
ByteBufferWriter::ORDER_NETWORK};
|
||||
for (size_t i = 0; i < arraysize(orders); i++) {
|
||||
ByteBufferWriter buffer(orders[i]);
|
||||
EXPECT_EQ(orders[i], buffer.Order());
|
||||
ByteBufferReader read_buf(nullptr, 0, orders[i]);
|
||||
EXPECT_EQ(orders[i], read_buf.Order());
|
||||
ByteBufferWriter buffer;
|
||||
ByteBufferReader read_buf(nullptr, 0);
|
||||
uint8_t ru8;
|
||||
EXPECT_FALSE(read_buf.ReadUInt8(&ru8));
|
||||
|
||||
// Write and read uint8_t.
|
||||
uint8_t wu8 = 1;
|
||||
buffer.WriteUInt8(wu8);
|
||||
ByteBufferReader read_buf1(buffer.Data(), buffer.Length(), orders[i]);
|
||||
ByteBufferReader read_buf1(buffer.Data(), buffer.Length());
|
||||
EXPECT_TRUE(read_buf1.ReadUInt8(&ru8));
|
||||
EXPECT_EQ(wu8, ru8);
|
||||
EXPECT_EQ(0U, read_buf1.Length());
|
||||
|
@ -104,7 +99,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
|
|||
// Write and read uint16_t.
|
||||
uint16_t wu16 = (1 << 8) + 1;
|
||||
buffer.WriteUInt16(wu16);
|
||||
ByteBufferReader read_buf2(buffer.Data(), buffer.Length(), orders[i]);
|
||||
ByteBufferReader read_buf2(buffer.Data(), buffer.Length());
|
||||
uint16_t ru16;
|
||||
EXPECT_TRUE(read_buf2.ReadUInt16(&ru16));
|
||||
EXPECT_EQ(wu16, ru16);
|
||||
|
@ -114,7 +109,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
|
|||
// Write and read uint24.
|
||||
uint32_t wu24 = (3 << 16) + (2 << 8) + 1;
|
||||
buffer.WriteUInt24(wu24);
|
||||
ByteBufferReader read_buf3(buffer.Data(), buffer.Length(), orders[i]);
|
||||
ByteBufferReader read_buf3(buffer.Data(), buffer.Length());
|
||||
uint32_t ru24;
|
||||
EXPECT_TRUE(read_buf3.ReadUInt24(&ru24));
|
||||
EXPECT_EQ(wu24, ru24);
|
||||
|
@ -124,7 +119,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
|
|||
// Write and read uint32_t.
|
||||
uint32_t wu32 = (4 << 24) + (3 << 16) + (2 << 8) + 1;
|
||||
buffer.WriteUInt32(wu32);
|
||||
ByteBufferReader read_buf4(buffer.Data(), buffer.Length(), orders[i]);
|
||||
ByteBufferReader read_buf4(buffer.Data(), buffer.Length());
|
||||
uint32_t ru32;
|
||||
EXPECT_TRUE(read_buf4.ReadUInt32(&ru32));
|
||||
EXPECT_EQ(wu32, ru32);
|
||||
|
@ -135,7 +130,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
|
|||
uint32_t another32 = (8 << 24) + (7 << 16) + (6 << 8) + 5;
|
||||
uint64_t wu64 = (static_cast<uint64_t>(another32) << 32) + wu32;
|
||||
buffer.WriteUInt64(wu64);
|
||||
ByteBufferReader read_buf5(buffer.Data(), buffer.Length(), orders[i]);
|
||||
ByteBufferReader read_buf5(buffer.Data(), buffer.Length());
|
||||
uint64_t ru64;
|
||||
EXPECT_TRUE(read_buf5.ReadUInt64(&ru64));
|
||||
EXPECT_EQ(wu64, ru64);
|
||||
|
@ -145,7 +140,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
|
|||
// Write and read string.
|
||||
std::string write_string("hello");
|
||||
buffer.WriteString(write_string);
|
||||
ByteBufferReader read_buf6(buffer.Data(), buffer.Length(), orders[i]);
|
||||
ByteBufferReader read_buf6(buffer.Data(), buffer.Length());
|
||||
std::string read_string;
|
||||
EXPECT_TRUE(read_buf6.ReadString(&read_string, write_string.size()));
|
||||
EXPECT_EQ(write_string, read_string);
|
||||
|
@ -155,7 +150,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
|
|||
// Write and read bytes
|
||||
char write_bytes[] = "foo";
|
||||
buffer.WriteBytes(write_bytes, 3);
|
||||
ByteBufferReader read_buf7(buffer.Data(), buffer.Length(), orders[i]);
|
||||
ByteBufferReader read_buf7(buffer.Data(), buffer.Length());
|
||||
char read_bytes[3];
|
||||
EXPECT_TRUE(read_buf7.ReadBytes(read_bytes, 3));
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
|
@ -167,7 +162,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
|
|||
// Write and read reserved buffer space
|
||||
char* write_dst = buffer.ReserveWriteBuffer(3);
|
||||
memcpy(write_dst, write_bytes, 3);
|
||||
ByteBufferReader read_buf8(buffer.Data(), buffer.Length(), orders[i]);
|
||||
ByteBufferReader read_buf8(buffer.Data(), buffer.Length());
|
||||
memset(read_bytes, 0, 3);
|
||||
EXPECT_TRUE(read_buf8.ReadBytes(read_bytes, 3));
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
|
@ -182,7 +177,7 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
|
|||
buffer.WriteUInt24(wu24);
|
||||
buffer.WriteUInt32(wu32);
|
||||
buffer.WriteUInt64(wu64);
|
||||
ByteBufferReader read_buf9(buffer.Data(), buffer.Length(), orders[i]);
|
||||
ByteBufferReader read_buf9(buffer.Data(), buffer.Length());
|
||||
EXPECT_TRUE(read_buf9.ReadUInt8(&ru8));
|
||||
EXPECT_EQ(wu8, ru8);
|
||||
EXPECT_TRUE(read_buf9.ReadUInt16(&ru16));
|
||||
|
@ -195,14 +190,10 @@ TEST(ByteBufferTest, TestReadWriteBuffer) {
|
|||
EXPECT_EQ(wu64, ru64);
|
||||
EXPECT_EQ(0U, read_buf9.Length());
|
||||
buffer.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ByteBufferTest, TestReadWriteUVarint) {
|
||||
ByteBufferWriter::ByteOrder orders[2] = {ByteBufferWriter::ORDER_HOST,
|
||||
ByteBufferWriter::ORDER_NETWORK};
|
||||
for (ByteBufferWriter::ByteOrder& order : orders) {
|
||||
ByteBufferWriter write_buffer(order);
|
||||
ByteBufferWriter write_buffer;
|
||||
size_t size = 0;
|
||||
EXPECT_EQ(size, write_buffer.Length());
|
||||
|
||||
|
@ -226,8 +217,7 @@ TEST(ByteBufferTest, TestReadWriteUVarint) {
|
|||
size += 6;
|
||||
EXPECT_EQ(size, write_buffer.Length());
|
||||
|
||||
ByteBufferReader read_buffer(write_buffer.Data(), write_buffer.Length(),
|
||||
order);
|
||||
ByteBufferReader read_buffer(write_buffer.Data(), write_buffer.Length());
|
||||
EXPECT_EQ(size, read_buffer.Length());
|
||||
uint64_t val1, val2, val3, val4, val5;
|
||||
|
||||
|
@ -255,7 +245,6 @@ TEST(ByteBufferTest, TestReadWriteUVarint) {
|
|||
EXPECT_EQ(68719476736u, val5);
|
||||
size -= 6;
|
||||
EXPECT_EQ(size, read_buffer.Length());
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace rtc
|
||||
|
|
|
@ -72,8 +72,6 @@ class MockKeyFrameRequestSender : public KeyFrameRequestSender {
|
|||
class MockOnCompleteFrameCallback
|
||||
: public video_coding::OnCompleteFrameCallback {
|
||||
public:
|
||||
MockOnCompleteFrameCallback() : buffer_(rtc::ByteBuffer::ORDER_NETWORK) {}
|
||||
|
||||
MOCK_METHOD1(DoOnCompleteFrame, void(video_coding::EncodedFrame* frame));
|
||||
MOCK_METHOD1(DoOnCompleteFrameFailNullptr,
|
||||
void(video_coding::EncodedFrame* frame));
|
||||
|
|
Loading…
Reference in a new issue