kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011 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 | */ |
kjellander@webrtc.org | 5b97b12 | 2011-12-08 07:42:18 +0000 | [diff] [blame] | 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef TEST_TESTSUPPORT_PACKET_READER_H_ |
| 12 | #define TEST_TESTSUPPORT_PACKET_READER_H_ |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 13 | |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 14 | #include <cstddef> |
Mirko Bonadei | 7120742 | 2017-09-15 13:58:09 +0200 | [diff] [blame^] | 15 | #include "typedefs.h" // NOLINT(build/include) |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | namespace test { |
| 19 | |
| 20 | // Reads chunks of data to simulate network packets from a byte array. |
| 21 | class PacketReader { |
| 22 | public: |
| 23 | PacketReader(); |
| 24 | virtual ~PacketReader(); |
| 25 | |
| 26 | // Inizializes a new reading operation. Must be done before invoking the |
| 27 | // NextPacket method. |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 28 | // * data_length_in_bytes is the length of the data byte array. |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 29 | // 0 length will result in no packets are read. |
| 30 | // * packet_size_in_bytes is the number of bytes to read in each NextPacket |
| 31 | // method call. Must be > 0 |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 32 | virtual void InitializeReading(uint8_t* data, size_t data_length_in_bytes, |
| 33 | size_t packet_size_in_bytes); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 34 | |
| 35 | // Moves the supplied pointer to the beginning of the next packet. |
| 36 | // Returns: |
| 37 | // * The size of the packet ready to read (lower than the packet size for |
| 38 | // the last packet) |
| 39 | // * 0 if there are no more packets to read |
| 40 | // * -1 if InitializeReading has not been called (also prints to stderr). |
pbos@webrtc.org | a5f1787 | 2013-04-09 11:10:21 +0000 | [diff] [blame] | 41 | virtual int NextPacket(uint8_t** packet_pointer); |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 42 | |
| 43 | private: |
pbos@webrtc.org | a5f1787 | 2013-04-09 11:10:21 +0000 | [diff] [blame] | 44 | uint8_t* data_; |
pkasting@chromium.org | 4591fbd | 2014-11-20 22:28:14 +0000 | [diff] [blame] | 45 | size_t data_length_; |
| 46 | size_t packet_size_; |
| 47 | size_t currentIndex_; |
kjellander@webrtc.org | 35a1756 | 2011-10-06 06:44:54 +0000 | [diff] [blame] | 48 | bool initialized_; |
| 49 | }; |
| 50 | |
| 51 | } // namespace test |
| 52 | } // namespace webrtc |
| 53 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 54 | #endif // TEST_TESTSUPPORT_PACKET_READER_H_ |