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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 size_t Length() const { return end_ - start_; } | 50 size_t Length() const { return end_ - start_; } |
51 size_t Capacity() const { return size_ - start_; } | 51 size_t Capacity() const { return size_ - start_; } |
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 WriteString(const std::string& val); | 61 void WriteString(const std::string& val); |
61 void WriteBytes(const char* val, size_t len); | 62 void WriteBytes(const char* val, size_t len); |
62 | 63 |
63 // 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 |
64 // 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 |
65 // ByteBufferWriter. | 66 // ByteBufferWriter. |
66 char* ReserveWriteBuffer(size_t len); | 67 char* ReserveWriteBuffer(size_t len); |
67 | 68 |
68 // Resize the buffer to the specified |size|. | 69 // Resize the buffer to the specified |size|. |
69 void Resize(size_t size); | 70 void Resize(size_t size); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 // Returns number of unprocessed bytes. | 104 // Returns number of unprocessed bytes. |
104 size_t Length() const { return end_ - start_; } | 105 size_t Length() const { return end_ - start_; } |
105 | 106 |
106 // Read a next value from the buffer. Return false if there isn't | 107 // Read a next value from the buffer. Return false if there isn't |
107 // enough data left for the specified type. | 108 // enough data left for the specified type. |
108 bool ReadUInt8(uint8_t* val); | 109 bool ReadUInt8(uint8_t* val); |
109 bool ReadUInt16(uint16_t* val); | 110 bool ReadUInt16(uint16_t* val); |
110 bool ReadUInt24(uint32_t* val); | 111 bool ReadUInt24(uint32_t* val); |
111 bool ReadUInt32(uint32_t* val); | 112 bool ReadUInt32(uint32_t* val); |
112 bool ReadUInt64(uint64_t* val); | 113 bool ReadUInt64(uint64_t* val); |
| 114 bool ReadUVarint(uint64_t* val); |
113 bool ReadBytes(char* val, size_t len); | 115 bool ReadBytes(char* val, size_t len); |
114 | 116 |
115 // Appends next |len| bytes from the buffer to |val|. Returns false | 117 // Appends next |len| bytes from the buffer to |val|. Returns false |
116 // if there is less than |len| bytes left. | 118 // if there is less than |len| bytes left. |
117 bool ReadString(std::string* val, size_t len); | 119 bool ReadString(std::string* val, size_t len); |
118 | 120 |
119 // Moves current position |size| bytes forward. Returns false if | 121 // Moves current position |size| bytes forward. Returns false if |
120 // there is less than |size| bytes left in the buffer. Consume doesn't | 122 // there is less than |size| bytes left in the buffer. Consume doesn't |
121 // permanently remove data, so remembered read positions are still valid | 123 // permanently remove data, so remembered read positions are still valid |
122 // after this call. | 124 // after this call. |
123 bool Consume(size_t size); | 125 bool Consume(size_t size); |
124 | 126 |
125 private: | 127 private: |
126 void Construct(const char* bytes, size_t size); | 128 void Construct(const char* bytes, size_t size); |
127 | 129 |
128 const char* bytes_; | 130 const char* bytes_; |
129 size_t size_; | 131 size_t size_; |
130 size_t start_; | 132 size_t start_; |
131 size_t end_; | 133 size_t end_; |
132 | 134 |
133 RTC_DISALLOW_COPY_AND_ASSIGN(ByteBufferReader); | 135 RTC_DISALLOW_COPY_AND_ASSIGN(ByteBufferReader); |
134 }; | 136 }; |
135 | 137 |
136 } // namespace rtc | 138 } // namespace rtc |
137 | 139 |
138 #endif // WEBRTC_BASE_BYTEBUFFER_H_ | 140 #endif // WEBRTC_BASE_BYTEBUFFER_H_ |
OLD | NEW |