blob: e84ecd96b5fa3150708310f564cdbc5deb00a035 [file] [log] [blame]
kjellander@webrtc.org35a17562011-10-06 06:44:54 +00001/*
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.org5b97b122011-12-08 07:42:18 +000010
11#ifndef WEBRTC_TEST_TESTSUPPORT_PACKET_READER_H_
12#define WEBRTC_TEST_TESTSUPPORT_PACKET_READER_H_
kjellander@webrtc.org35a17562011-10-06 06:44:54 +000013
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000014#include "webrtc/typedefs.h"
kjellander@webrtc.org35a17562011-10-06 06:44:54 +000015
16namespace webrtc {
17namespace test {
18
19// Reads chunks of data to simulate network packets from a byte array.
20class PacketReader {
21 public:
22 PacketReader();
23 virtual ~PacketReader();
24
25 // Inizializes a new reading operation. Must be done before invoking the
26 // NextPacket method.
27 // * data_length_in_bytes is the length of the data byte array. Must be >= 0.
28 // 0 length will result in no packets are read.
29 // * packet_size_in_bytes is the number of bytes to read in each NextPacket
30 // method call. Must be > 0
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000031 virtual void InitializeReading(uint8_t* data, int data_length_in_bytes,
kjellander@webrtc.org35a17562011-10-06 06:44:54 +000032 int packet_size_in_bytes);
33
34 // Moves the supplied pointer to the beginning of the next packet.
35 // Returns:
36 // * The size of the packet ready to read (lower than the packet size for
37 // the last packet)
38 // * 0 if there are no more packets to read
39 // * -1 if InitializeReading has not been called (also prints to stderr).
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000040 virtual int NextPacket(uint8_t** packet_pointer);
kjellander@webrtc.org35a17562011-10-06 06:44:54 +000041
42 private:
pbos@webrtc.orga5f17872013-04-09 11:10:21 +000043 uint8_t* data_;
kjellander@webrtc.org35a17562011-10-06 06:44:54 +000044 int data_length_;
45 int packet_size_;
46 int currentIndex_;
47 bool initialized_;
48};
49
50} // namespace test
51} // namespace webrtc
52
kjellander@webrtc.org5b97b122011-12-08 07:42:18 +000053#endif // WEBRTC_TEST_TESTSUPPORT_PACKET_READER_H_