| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 class ByteBufferWriter : public ByteBuffer { | 39 class ByteBufferWriter : public ByteBuffer { |
| 40 public: | 40 public: |
| 41 // |byte_order| defines order of bytes in the buffer. | 41 // |byte_order| defines order of bytes in the buffer. |
| 42 ByteBufferWriter(); | 42 ByteBufferWriter(); |
| 43 explicit ByteBufferWriter(ByteOrder byte_order); | 43 explicit ByteBufferWriter(ByteOrder byte_order); |
| 44 ByteBufferWriter(const char* bytes, size_t len); | 44 ByteBufferWriter(const char* bytes, size_t len); |
| 45 ByteBufferWriter(const char* bytes, size_t len, ByteOrder byte_order); | 45 ByteBufferWriter(const char* bytes, size_t len, ByteOrder byte_order); |
| 46 | 46 |
| 47 ~ByteBufferWriter(); | 47 ~ByteBufferWriter(); |
| 48 | 48 |
| 49 const char* Data() const { return bytes_ + start_; } | 49 const char* Data() const { return bytes_; } |
| 50 size_t Length() const { return end_ - start_; } | 50 size_t Length() const { return end_; } |
| 51 size_t Capacity() const { return size_ - start_; } | 51 size_t Capacity() const { return size_; } |
| 52 | 52 |
| 53 // Write value to the buffer. Resizes the buffer when it is | 53 // Write value to the buffer. Resizes the buffer when it is |
| 54 // neccessary. | 54 // neccessary. |
| 55 void WriteUInt8(uint8_t val); | 55 void WriteUInt8(uint8_t val); |
| 56 void WriteUInt16(uint16_t val); | 56 void WriteUInt16(uint16_t val); |
| 57 void WriteUInt24(uint32_t val); | 57 void WriteUInt24(uint32_t val); |
| 58 void WriteUInt32(uint32_t val); | 58 void WriteUInt32(uint32_t val); |
| 59 void WriteUInt64(uint64_t val); | 59 void WriteUInt64(uint64_t val); |
| 60 void WriteUVarint(uint64_t val); | 60 void WriteUVarint(uint64_t val); |
| 61 void WriteString(const std::string& val); | 61 void WriteString(const std::string& val); |
| 62 void WriteBytes(const char* val, size_t len); | 62 void WriteBytes(const char* val, size_t len); |
| 63 | 63 |
| 64 // Reserves the given number of bytes and returns a char* that can be written | 64 // Reserves the given number of bytes and returns a char* that can be written |
| 65 // into. Useful for functions that require a char* buffer and not a | 65 // into. Useful for functions that require a char* buffer and not a |
| 66 // ByteBufferWriter. | 66 // ByteBufferWriter. |
| 67 char* ReserveWriteBuffer(size_t len); | 67 char* ReserveWriteBuffer(size_t len); |
| 68 | 68 |
| 69 // Resize the buffer to the specified |size|. | 69 // Resize the buffer to the specified |size|. |
| 70 void Resize(size_t size); | 70 void Resize(size_t size); |
| 71 | 71 |
| 72 // Clears the contents of the buffer. After this, Length() will be 0. | 72 // Clears the contents of the buffer. After this, Length() will be 0. |
| 73 void Clear(); | 73 void Clear(); |
| 74 | 74 |
| 75 private: | 75 private: |
| 76 void Construct(const char* bytes, size_t size); | 76 void Construct(const char* bytes, size_t size); |
| 77 | 77 |
| 78 char* bytes_; | 78 char* bytes_; |
| 79 size_t size_; | 79 size_t size_; |
| 80 size_t start_; | |
| 81 size_t end_; | 80 size_t end_; |
| 82 | 81 |
| 83 // There are sensible ways to define these, but they aren't needed in our code | 82 // There are sensible ways to define these, but they aren't needed in our code |
| 84 // base. | 83 // base. |
| 85 RTC_DISALLOW_COPY_AND_ASSIGN(ByteBufferWriter); | 84 RTC_DISALLOW_COPY_AND_ASSIGN(ByteBufferWriter); |
| 86 }; | 85 }; |
| 87 | 86 |
| 88 // The ByteBufferReader references the passed data, i.e. the pointer must be | 87 // The ByteBufferReader references the passed data, i.e. the pointer must be |
| 89 // valid during the lifetime of the reader. | 88 // valid during the lifetime of the reader. |
| 90 class ByteBufferReader : public ByteBuffer { | 89 class ByteBufferReader : public ByteBuffer { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 size_t size_; | 130 size_t size_; |
| 132 size_t start_; | 131 size_t start_; |
| 133 size_t end_; | 132 size_t end_; |
| 134 | 133 |
| 135 RTC_DISALLOW_COPY_AND_ASSIGN(ByteBufferReader); | 134 RTC_DISALLOW_COPY_AND_ASSIGN(ByteBufferReader); |
| 136 }; | 135 }; |
| 137 | 136 |
| 138 } // namespace rtc | 137 } // namespace rtc |
| 139 | 138 |
| 140 #endif // WEBRTC_BASE_BYTEBUFFER_H_ | 139 #endif // WEBRTC_BASE_BYTEBUFFER_H_ |
| OLD | NEW |