Bumping manifests a=b2g-bump
[gecko.git] / media / mtransport / databuffer.h
blobfe5b9a779ce49f32d311c890c7af43b716b7080c
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // Original author: ekr@rtfm.com
9 #ifndef databuffer_h__
10 #define databuffer_h__
11 #include <algorithm>
12 #include <mozilla/UniquePtr.h>
13 #include <m_cpp_utils.h>
14 #include <nsISupportsImpl.h>
16 namespace mozilla {
18 class DataBuffer {
19 public:
20 DataBuffer() : data_(nullptr), len_(0) {}
21 DataBuffer(const uint8_t *data, size_t len) {
22 Assign(data, len);
25 void Assign(const uint8_t *data, size_t len) {
26 Allocate(len);
27 memcpy(static_cast<void *>(data_.get()),
28 static_cast<const void *>(data), len);
31 void Allocate(size_t len) {
32 data_.reset(new uint8_t[len ? len : 1]); // Don't depend on new [0].
33 len_ = len;
36 const uint8_t *data() const { return data_.get(); }
37 uint8_t *data() { return data_.get(); }
38 size_t len() const { return len_; }
39 const bool empty() const { return len_ != 0; }
41 private:
42 UniquePtr<uint8_t[]> data_;
43 size_t len_;
45 DISALLOW_COPY_ASSIGN(DataBuffer);
50 #endif