diff --git a/packager/media/base/buffer_writer.cc b/packager/media/base/buffer_writer.cc index e5527d9983..d3c32fece3 100644 --- a/packager/media/base/buffer_writer.cc +++ b/packager/media/base/buffer_writer.cc @@ -55,6 +55,10 @@ void BufferWriter::AppendVector(const std::vector& v) { buf_.insert(buf_.end(), v.begin(), v.end()); } +void BufferWriter::AppendString(const std::string& s) { + buf_.insert(buf_.end(), s.begin(), s.end()); +} + void BufferWriter::AppendArray(const uint8_t* buf, size_t size) { buf_.insert(buf_.end(), buf, buf + size); } diff --git a/packager/media/base/buffer_writer.h b/packager/media/base/buffer_writer.h index 4ae0e60e06..6abc978dfe 100644 --- a/packager/media/base/buffer_writer.h +++ b/packager/media/base/buffer_writer.h @@ -48,6 +48,7 @@ class BufferWriter { void AppendNBytes(uint64_t v, size_t num_bytes); void AppendVector(const std::vector& v); + void AppendString(const std::string& s); void AppendArray(const uint8_t* buf, size_t size); void AppendBuffer(const BufferWriter& buffer); diff --git a/packager/media/base/buffer_writer_unittest.cc b/packager/media/base/buffer_writer_unittest.cc index f6403eb22e..f6f7ffdab5 100644 --- a/packager/media/base/buffer_writer_unittest.cc +++ b/packager/media/base/buffer_writer_unittest.cc @@ -110,6 +110,18 @@ TEST_F(BufferWriterTest, AppendVector) { ASSERT_EQ(v, data_read); } +TEST_F(BufferWriterTest, AppendString) { + const char kTestData[] = "test_data"; + writer_->AppendString(kTestData); + // -1 to remove the null terminating character. + ASSERT_EQ(strlen(kTestData), writer_->Size()); + + CreateReader(); + std::string data_read; + ASSERT_TRUE(reader_->ReadToString(&data_read, strlen(kTestData))); + ASSERT_EQ(kTestData, data_read); +} + TEST_F(BufferWriterTest, AppendArray) { writer_->AppendArray(kuint8Array, sizeof(kuint8Array)); ASSERT_EQ(sizeof(kuint8Array), writer_->Size());