blob: baba89e014316607eeb6ec3ef29bcdc75f37beda [file] [log] [blame]
Qingsi Wang558b93b2018-08-30 10:38:44 -07001/*
2 * Copyright 2018 The WebRTC Project Authors. All rights reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11#ifndef RTC_BASE_MESSAGE_BUFFER_READER_H_
12#define RTC_BASE_MESSAGE_BUFFER_READER_H_
13
14#include "rtc_base/bytebuffer.h"
15
16namespace webrtc {
17
18// A simple subclass of the ByteBufferReader that exposes the starting address
19// of the message and its length, so that we can recall previously parsed data.
20class MessageBufferReader : public rtc::ByteBufferReader {
21 public:
22 MessageBufferReader(const char* bytes, size_t len)
23 : rtc::ByteBufferReader(bytes, len) {}
24 ~MessageBufferReader() = default;
25
26 // Starting address of the message.
27 const char* MessageData() const { return bytes_; }
28 // Total length of the message. Note that this is different from Length(),
29 // which is the length of the remaining message from the current offset.
30 size_t MessageLength() const { return size_; }
31 // Current offset in the message.
32 size_t CurrentOffset() const { return start_; }
33};
34
35} // namespace webrtc
36
37#endif // RTC_BASE_MESSAGE_BUFFER_READER_H_