15 #include "fltRecordReader.h" 16 #include "config_flt.h" 18 #include "datagramIterator.h" 28 FltRecordReader(istream &in) :
36 _next_opcode = FO_none;
37 _next_record_length = 0;
64 nassertr(_state == S_normal, FO_none);
76 nassertr(_state == S_normal, *_iterator);
90 nassertr(_state == S_normal, bogus_datagram);
103 return _record_length;
115 if (_state == S_eof) {
116 assert(!flt_error_abort);
117 return FE_end_of_file;
119 if (_state == S_error) {
120 assert(!flt_error_abort);
121 return FE_read_error;
128 if (_next_error == FE_end_of_file) {
133 assert(!flt_error_abort);
134 return FE_end_of_file;
136 }
else if (_next_error != FE_ok) {
138 assert(!flt_error_abort);
142 _opcode = _next_opcode;
143 _record_length = _next_record_length;
145 if (flt_cat.is_debug()) {
147 <<
"Reading " << _opcode
148 <<
" of length " << _record_length <<
"\n";
152 int length = _next_record_length - header_size;
153 char *buffer =
new char[length];
155 _in.read(buffer, length);
157 _datagram =
Datagram(buffer, length);
162 assert(!flt_error_abort);
163 return FE_end_of_file;
168 assert(!flt_error_abort);
169 return FE_read_error;
174 while (_next_error == FE_ok && _next_opcode == FO_continuation) {
175 if (flt_cat.is_debug()) {
177 <<
"Reading continuation of length " << _next_record_length <<
"\n";
181 _record_length += _next_record_length;
182 length = _next_record_length - header_size;
184 buffer =
new char[length];
186 _in.read(buffer, length);
193 assert(!flt_error_abort);
194 return FE_end_of_file;
199 assert(!flt_error_abort);
200 return FE_read_error;
221 return _state == S_eof;
232 return _state == S_error;
246 void FltRecordReader::
248 char bytes[header_size];
249 _in.read(bytes, header_size);
252 _next_error = FE_end_of_file;
255 }
else if (_in.fail()) {
256 _next_error = FE_read_error;
266 if (_next_record_length < header_size) {
267 _next_error = FE_invalid_record;
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)...
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.
PN_int16 get_be_int16()
Extracts a signed 16-bit big-endian integer.
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. ...
PN_uint16 get_be_uint16()
Extracts an unsigned 16-bit big-endian integer.
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.