Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __BUFFER_H__
00020 #define __BUFFER_H__ 1
00021
00022 #ifdef HAVE_CONFIG_H
00023 #include "gnashconfig.h"
00024 #endif
00025
00026 #include <vector>
00027 #include <boost/cstdint.hpp>
00028 #include <boost/scoped_array.hpp>
00029 #include <boost/shared_ptr.hpp>
00030 #include <iostream>
00031 #include <string>
00032
00033 #include "getclocktime.hpp"
00034 #include "amf.h"
00035 #include "element.h"
00036 #include "dsodefs.h"
00037
00038
00039
00043 namespace cygnal
00044 {
00045
00046
00047 const size_t NETBUFSIZE = 1448;
00048
00049
00056 class DSOEXPORT Buffer
00057 {
00058 public:
00060 Buffer();
00062 Buffer(size_t nbytes);
00063
00069 Buffer(const std::string &str);
00070
00072 ~Buffer();
00073
00081 int corrupt();
00082 int corrupt(int factor);
00083
00092 Buffer &hex2mem(const std::string &str);
00093
00105 std::string hexify();
00106 std::string hexify(bool ascii);
00107 std::string hexify(Buffer &buf, bool ascii);
00108
00113 void clear();
00114
00118 bool empty() { return (_seekptr) ? false : true; };
00119
00129 Buffer &resize();
00139 Buffer &resize(size_t nbytes);
00140
00150 Buffer ©(boost::uint8_t *data, size_t nbytes);
00151
00158 Buffer &operator=(Buffer &buf);
00159 Buffer &operator=(boost::shared_ptr<Buffer>& buf);
00167 Buffer &operator=(const std::string &str);
00168 Buffer &operator=(const char *str);
00175 Buffer &operator=(double num);
00182 Buffer &operator=(boost::uint16_t length);
00189 Buffer &operator=(boost::uint8_t byte);
00196 Buffer &operator=(boost::uint8_t *byte);
00203 Buffer &operator=(cygnal::Element::amf0_type_e type);
00210 Buffer &operator=(bool flag);
00211
00220 Buffer &append(boost::uint8_t *data, size_t nbytes);
00221
00227 Buffer &operator+=(Buffer &buf);
00228 Buffer &operator+=(boost::shared_ptr<Buffer> &buf);
00229
00236 Buffer &operator+=(const std::string &str);
00237 Buffer &operator+=(const char *str);
00243 Buffer &operator+=(double num);
00244
00250 Buffer &operator+=(boost::uint32_t length);
00256 Buffer &operator+=(boost::uint16_t length);
00262 Buffer &operator+=(boost::uint8_t byte);
00263 Buffer &operator+=(char byte);
00269 Buffer &operator+=(cygnal::Element::amf0_type_e type);
00275 Buffer &operator+=(bool);
00276
00285 boost::uint8_t *remove(boost::uint8_t c);
00295 boost::uint8_t *remove(int index);
00310 boost::uint8_t *remove(int start, int range);
00311
00312
00316 boost::uint8_t *begin() { return _data.get() ; };
00317 boost::uint8_t *reference() { return _data.get(); }
00318 const boost::uint8_t *reference() const { return _data.get(); }
00319
00325 boost::uint8_t *end() { return _seekptr; };
00326
00330 size_t size() { return _nbytes; }
00331
00341 void setSize(size_t nbytes) { _nbytes = nbytes; };
00342
00344 void setPointer(boost::uint8_t *ptr) { _data.reset(ptr); };
00345
00354 bool operator==(Buffer &buf);
00355
00362 boost::uint8_t operator[](int index) { return _data[index]; };
00363
00370 boost::uint8_t *at(int index) { return _data.get() + index; };
00371
00377 size_t spaceLeft() { return (_nbytes - (_seekptr - _data.get())); };
00378
00384 size_t allocated() { return (_seekptr - _data.get()); };
00385
00391 void setSeekPointer(boost::uint8_t *ptr) { _seekptr = ptr; };
00392 void setSeekPointer(off_t offset) { _seekptr = _data.get() + offset; };
00393
00396 void dump() const { dump(std::cerr); }
00398 void dump(std::ostream& os) const;
00399
00400 protected:
00404 boost::uint8_t *_seekptr;
00405
00409 boost::scoped_array<boost::uint8_t> _data;
00410
00413 size_t _nbytes;
00418 #ifdef USE_STATS_BUFFERS
00419 struct timespec _stamp;
00420 #endif
00421
00422 private:
00430 Buffer &init(size_t nbytes);
00431
00437 boost::uint8_t hex2digit (boost::uint8_t digit);
00438 };
00439
00441 inline std::ostream& operator << (std::ostream& os, const Buffer& buf)
00442 {
00443 buf.dump(os);
00444 return os;
00445 }
00446
00447 }
00448
00449 #endif // end of __BUFFER_H__
00450
00451
00452
00453
00454