Added functional variants of Buffer::SetData and Buffer::AppendData.

They are invoked with the maximum size of the data to be added, and a
callable that generates that data, like this:

buffer.AppendData(10, [] (rtc::ArrayView<uint8_t> av) {
    for (uint8_t i = 0; i != 5; ++i)
      av[i] = i;

    return 5;
  });

The callable returns the number of bytes actually written, and the
final Buffer size will be adjusted accordingly. SetData and AppendData
both return the number of bytes added (i.e. the return value of the
callable).

These versions will be useful when converting AudioEncoder::Encode to use Buffer rather than raw pointers.

Also added a few tests for the new functionality.

Review URL: https://codereview.webrtc.org/1717273002

Cr-Commit-Position: refs/heads/master@{#11733}
This commit is contained in:
ossu
2016-02-24 01:05:56 -08:00
committed by Commit bot
parent 17849fcc8b
commit b01c7816a8
4 changed files with 147 additions and 5 deletions

View File

@ -10,6 +10,7 @@
#include "webrtc/base/buffer.h"
#include <algorithm>
#include <cassert>
#include <utility>