Panda3D
datagramBuffer.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file datagramBuffer.h
10  * @author rdb
11  * @date 2017-11-07
12  */
13 
14 #ifndef DATAGRAMBUFFER_H
15 #define DATAGRAMBUFFER_H
16 
17 #include "pandabase.h"
18 #include "datagramGenerator.h"
19 #include "datagramSink.h"
20 #include "vector_uchar.h"
21 
22 /**
23  * This class can be used to write a series of datagrams into a memory buffer.
24  * It acts as both a datagram sink and generator; you can fill it up with
25  * datagrams and then read as many datagrams from it.
26  *
27  * This uses the same format as DatagramInputFile and DatagramOutputFile,
28  * meaning that Datagram sizes are always stored little-endian.
29  */
30 class EXPCL_PANDA_PUTIL DatagramBuffer : public DatagramSink, public DatagramGenerator {
31 PUBLISHED:
32  INLINE DatagramBuffer();
33  INLINE explicit DatagramBuffer(vector_uchar data);
34 
35  INLINE void clear();
36 
37 public:
38  bool write_header(const std::string &header);
39  virtual bool put_datagram(const Datagram &data) override;
40  virtual void flush() override;
41 
42  bool read_header(std::string &header, size_t num_bytes);
43  virtual bool get_datagram(Datagram &data) override;
44  virtual bool is_eof() override;
45 
46  virtual bool is_error() override;
47 
48  INLINE const vector_uchar &get_data() const;
49  INLINE void set_data(vector_uchar data);
50  INLINE void swap_data(vector_uchar &other);
51 
52 PUBLISHED:
53  MAKE_PROPERTY(data, get_data, set_data);
54 
55 private:
56  vector_uchar _data;
57  size_t _read_offset;
58  bool _wrote_first_datagram;
59  bool _read_first_datagram;
60 };
61 
62 #include "datagramBuffer.I"
63 
64 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class defines the abstract interface to sending datagrams to any target, whether it be into a fi...
Definition: datagramSink.h:29
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This class can be used to write a series of datagrams into a memory buffer.
This class defines the abstract interace to any source of datagrams, whether it be from a file or fro...
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38