20 #ifndef GNASH_STREAM_H
21 #define GNASH_STREAM_H
30 #include <boost/cstdint.hpp>
71 unsigned read_uint(
unsigned short bitcount);
88 int read_sint(
unsigned short bitcount);
106 float read_short_ufixed();
112 float read_short_sfixed();
118 float read_short_float();
124 float read_long_float();
151 unsigned read(
char *buf,
unsigned count);
157 boost::uint8_t read_u8();
163 boost::int8_t read_s8();
169 boost::uint16_t read_u16();
175 boost::int16_t read_s16();
181 boost::uint32_t read_u32();
188 boost::int32_t read_s32();
197 boost::uint32_t read_V32()
200 boost::uint32_t res = read_u8();
201 if (!(res & 0x00000080))
return res;
204 res = (res & 0x0000007F) | read_u8() << 7;
205 if (!(res & 0x00004000))
return res;
208 res = (res & 0x00003FFF) | read_u8() << 14;
209 if (!(res & 0x00200000))
return res;
212 res = (res & 0x001FFFFF) | read_u8() << 21;
213 if (!(res & 0x10000000))
return res;
216 res = (res & 0x0FFFFFFF) | read_u8() << 28;
229 if (!(read_u8() & 0x80))
return;
231 if (!(read_u8() & 0x80))
return;
233 if (!(read_u8() & 0x80))
return;
235 if (!(read_u8() & 0x80))
return;
237 static_cast<void> (read_u8());
250 unsigned read_variable_count()
253 unsigned count = read_u8();
271 void read_string(std::string& to);
284 void read_string_with_length(std::string& to);
299 void read_string_with_length(
unsigned len, std::string& to);
310 unsigned long tell();
323 bool seek(
unsigned long pos);
326 unsigned long get_tag_end_position();
351 bool skip_bytes(
unsigned num)
355 size_t curpos = tell();
356 return seek(curpos+num);
360 void skip_to_tag_end()
363 seek(get_tag_end_position());
376 void ensureBytes(
unsigned long needed);
388 void ensureBits(
unsigned long needed)
390 #ifndef GNASH_TRUST_SWF_INPUT
391 if ( _tagBoundsStack.empty() )
return;
392 unsigned long int bytesLeft = get_tag_end_position() - tell();
393 unsigned long int bitsLeft = (bytesLeft*8)+m_unused_bits;
394 if ( bitsLeft < needed )
396 std::stringstream ss;
397 ss <<
"premature end of tag: need to read " << needed <<
" bytes, but only " << bitsLeft <<
" left in this tag";
424 boost::uint8_t m_current_byte;
425 boost::uint8_t m_unused_bits;
427 typedef std::pair<unsigned long,unsigned long> TagBoundaries;
429 std::vector<TagBoundaries> _tagBoundsStack;
436 #endif // GNASH_STREAM_H