message_buffer_reader.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  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. #ifndef RTC_BASE_MESSAGE_BUFFER_READER_H_
  11. #define RTC_BASE_MESSAGE_BUFFER_READER_H_
  12. #include "rtc_base/byte_buffer.h"
  13. namespace webrtc {
  14. // A simple subclass of the ByteBufferReader that exposes the starting address
  15. // of the message and its length, so that we can recall previously parsed data.
  16. class MessageBufferReader : public rtc::ByteBufferReader {
  17. public:
  18. MessageBufferReader(const char* bytes, size_t len)
  19. : rtc::ByteBufferReader(bytes, len) {}
  20. ~MessageBufferReader() = default;
  21. // Starting address of the message.
  22. const char* MessageData() const { return bytes_; }
  23. // Total length of the message. Note that this is different from Length(),
  24. // which is the length of the remaining message from the current offset.
  25. size_t MessageLength() const { return size_; }
  26. // Current offset in the message.
  27. size_t CurrentOffset() const { return start_; }
  28. };
  29. } // namespace webrtc
  30. #endif // RTC_BASE_MESSAGE_BUFFER_READER_H_