25 FltRecordReader(std::istream &in) :
33 _next_opcode = FO_none;
34 _next_record_length = 0;
45 if (_iterator !=
nullptr) {
56 nassertr(_state == S_normal, FO_none);
65 nassertr(_state == S_normal, *_iterator);
77 nassertr(_state == S_normal, bogus_datagram);
87 return _record_length;
96 if (_state == S_eof) {
97 assert(!flt_error_abort);
98 return FE_end_of_file;
100 if (_state == S_error) {
101 assert(!flt_error_abort);
102 return FE_read_error;
104 if (_iterator !=
nullptr) {
109 if (_next_error == FE_end_of_file) {
114 assert(!flt_error_abort);
115 return FE_end_of_file;
117 }
else if (_next_error != FE_ok) {
119 assert(!flt_error_abort);
123 _opcode = _next_opcode;
124 _record_length = _next_record_length;
126 if (flt_cat.is_debug()) {
128 <<
"Reading " << _opcode
129 <<
" of length " << _record_length <<
"\n";
133 int length = _next_record_length - header_size;
135 vector_uchar data((
size_t)length);
136 _in.read((
char *)&data[0], length);
137 _datagram =
Datagram(std::move(data));
145 assert(!flt_error_abort);
146 return FE_end_of_file;
150 assert(!flt_error_abort);
151 return FE_read_error;
156 while (_next_error == FE_ok && _next_opcode == FO_continuation) {
157 if (flt_cat.is_debug()) {
159 <<
"Reading continuation of length " << _next_record_length <<
"\n";
163 _record_length += _next_record_length;
164 length = _next_record_length - header_size;
167 char *buffer =
new char[length];
168 _in.read(buffer, length);
176 assert(!flt_error_abort);
177 return FE_end_of_file;
181 assert(!flt_error_abort);
182 return FE_read_error;
200 return _state == S_eof;
209 return _state == S_error;
220 void FltRecordReader::
222 char bytes[header_size];
223 _in.read(bytes, header_size);
227 _next_error = FE_end_of_file;
230 _next_error = FE_read_error;
237 _next_opcode = (FltOpcode)dgi.get_be_int16();
238 _next_record_length = dgi.get_be_uint16();
240 if (_next_record_length < header_size) {
241 _next_error = FE_invalid_record;
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void append_data(const void *data, size_t size)
Appends some more raw data to the end of the datagram.
const Datagram & get_datagram() const
Return the datagram of this iterator.
bool error() const
Returns true if some error has been encountered while reading (for instance, a truncated file).
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
DatagramIterator & get_iterator()
Returns an iterator suitable for extracting data from the current record.
const Datagram & get_datagram()
Returns the datagram representing the entire record, less the four-byte header.
FltOpcode get_opcode() const
Returns the opcode associated with the current record.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
FltError advance(bool ok_eof=false)
Extracts the next record from the file.
bool eof() const
Returns true if end-of-file has been reached without error.
int get_record_length() const
Returns the entire length of the record, including the four-byte header.