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;
134 char *buffer =
new char[length];
136 _in.read(buffer, length);
138 _datagram =
Datagram(buffer, length);
143 assert(!flt_error_abort);
144 return FE_end_of_file;
149 assert(!flt_error_abort);
150 return FE_read_error;
155 while (_next_error == FE_ok && _next_opcode == FO_continuation) {
156 if (flt_cat.is_debug()) {
158 <<
"Reading continuation of length " << _next_record_length <<
"\n";
162 _record_length += _next_record_length;
163 length = _next_record_length - header_size;
165 buffer =
new char[length];
167 _in.read(buffer, length);
174 assert(!flt_error_abort);
175 return FE_end_of_file;
180 assert(!flt_error_abort);
181 return FE_read_error;
199 return _state == S_eof;
208 return _state == S_error;
219 void FltRecordReader::
221 char bytes[header_size];
222 _in.read(bytes, header_size);
225 _next_error = FE_end_of_file;
228 }
else if (_in.fail()) {
229 _next_error = FE_read_error;
236 _next_opcode = (FltOpcode)dgi.get_be_int16();
237 _next_record_length = dgi.get_be_uint16();
239 if (_next_record_length < header_size) {
240 _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.