24 nassertr(!_wrote_first_datagram,
false);
26 _data.insert(_data.end(), header.begin(), header.end());
36 _wrote_first_datagram =
true;
39 size_t num_bytes = data.get_length();
40 size_t offset = _data.size();
42 if (num_bytes == (uint32_t)-1 || num_bytes != (uint32_t)num_bytes) {
44 _data.resize(offset + num_bytes + 4 +
sizeof(uint64_t));
45 _data[offset++] = 0xff;
46 _data[offset++] = 0xff;
47 _data[offset++] = 0xff;
48 _data[offset++] = 0xff;
51 memcpy(&_data[offset], s.
get_data(),
sizeof(uint64_t));
52 offset +=
sizeof(uint64_t);
55 _data.resize(offset + num_bytes +
sizeof(uint32_t));
58 memcpy(&_data[offset], s.
get_data(),
sizeof(uint32_t));
59 offset +=
sizeof(uint32_t);
63 memcpy(&_data[offset], data.get_data(), data.get_length());
82 nassertr(!_read_first_datagram,
false);
83 if (_read_offset + num_bytes > _data.size()) {
87 header = std::string((
char *)&_data[_read_offset], num_bytes);
88 _read_offset += num_bytes;
98 _read_first_datagram =
true;
99 if (_read_offset +
sizeof(uint32_t) > _data.size()) {
105 uint32_t num_bytes_32;
106 LittleEndian s(&_data[_read_offset], 0,
sizeof(uint32_t));
110 if (num_bytes_32 == 0) {
117 size_t num_bytes = (size_t)num_bytes_32;
118 if (num_bytes_32 == (uint32_t)-1) {
120 uint64_t num_bytes_64;
121 LittleEndian s(&_data[_read_offset], 0,
sizeof(uint64_t));
125 num_bytes = (size_t)num_bytes_64;
126 nassertr((uint64_t)num_bytes == num_bytes_64,
false);
130 nassertr_always(_read_offset + num_bytes <= _data.size(),
false);
132 data =
Datagram(&_data[_read_offset], num_bytes);
133 _read_offset += num_bytes;
143 return (_read_offset +
sizeof(uint32_t)) > _data.size();
bool write_header(const std::string &header)
Writes a sequence of bytes to the beginning of the datagram file.
virtual bool is_error() override
Returns true if the buffer has reached an error condition.
virtual bool is_eof() override
Returns true if the buffer has reached the end-of-buffer.
const void * get_data() const
Returns the pointer to the first byte of the data, either reversed or nonreversed,...
NativeNumericData and ReversedNumericData work together to provide a sneaky interface for automatical...
virtual bool put_datagram(const Datagram &data) override
Writes the given datagram to the file.
virtual void flush() override
This does absolutely nothing.
void store_value(void *dest, size_t length) const
Copies the data, with byte reversal if appropriate, into the indicated numeric variable,...
bool read_header(std::string &header, size_t num_bytes)
Reads a sequence of bytes from the beginning of the datagram file.
virtual bool get_datagram(Datagram &data) override
Reads the next datagram from the file.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.