2
// Copyright (C) 2008 Free Software Foundation, Inc.
4
// This program is free software; you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation; either version 3 of the License, or
7
// (at your option) any later version.
9
// This program is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
// GNU General Public License for more details.
14
// You should have received a copy of the GNU General Public License
15
// along with this program; if not, write to the Free Software
16
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#define __BUFFER_H__ 1
22
#include <boost/cstdint.hpp>
25
#include "getclocktime.hpp"
31
// _definst_ is the default instance name
35
class DSOEXPORT Buffer
39
// Create with a size other than the default
40
Buffer(size_t nbytes);
42
// Delete the allocate memory
45
bool empty() { return (_seekptr)?true:false; };
47
// Resize the buffer that holds the data
49
void *resize(size_t nbytes);
51
// Put data into the buffer. This overwrites all data, and resets the seek ptr.
52
void copy(gnash::Network::byte_t *data, size_t nbytes);
53
void copy(gnash::Network::byte_t *data) { copy(data, _nbytes); };
54
void copy(const std::string &str);
55
void copy(double num);
56
void copy(boost::uint16_t length);
57
void copy(gnash::Network::byte_t byte);
59
// void copy(boost::uint32_t val);
60
// void copy(Element::amf_type_e type);
62
// Append data to the existing data in the buffer. This assume the
63
// buffer has been sized to hold the data as it is appended.
64
gnash::Network::byte_t *append(Buffer *buf);
65
gnash::Network::byte_t *append(Buffer &buf);
66
gnash::Network::byte_t *append(boost::uint32_t val);
67
gnash::Network::byte_t *append(bool);
68
gnash::Network::byte_t *append(double num);
69
gnash::Network::byte_t *append(Element::amf0_type_e type);
70
gnash::Network::byte_t *append(boost::uint16_t length);
71
gnash::Network::byte_t *append(gnash::Network::byte_t *data, size_t nbytes);
72
gnash::Network::byte_t *append(gnash::Network::byte_t byte);
73
gnash::Network::byte_t *append(const std::string &str);
75
// Find a byte in the buffer
76
// Network::byte_t *find(char c);
77
gnash::Network::byte_t *find(gnash::Network::byte_t b);
78
gnash::Network::byte_t *find(gnash::Network::byte_t *b, size_t size);
80
// Drop a byte or range of characters without resizing
81
// Network::byte_t *remove(char c);
82
gnash::Network::byte_t *remove(gnash::Network::byte_t c);
83
gnash::Network::byte_t *remove(int x);
84
gnash::Network::byte_t *remove(int x, int y);
87
gnash::Network::byte_t *begin() { return _ptr ; };
88
gnash::Network::byte_t *end() { return _ptr + _nbytes; };
89
gnash::Network::byte_t *reference() { return _ptr; }
90
size_t size() { return _nbytes; }
91
void setSize(size_t nbytes) { _nbytes = nbytes; };
93
// make ourselves be able to be copied.
94
Buffer &operator=(Buffer *buf);
95
Buffer &operator=(Buffer &buf);
97
// Test against other buffers
98
bool operator==(Buffer *buf);
99
bool operator==(Buffer &buf);
100
Buffer &operator+=(Buffer *buf);
101
Buffer &operator+=(gnash::Network::byte_t byte);
102
Buffer &operator+=(char byte);
103
Buffer &operator+=(Buffer &buf);
104
gnash::Network::byte_t operator[](int x) { return *(_ptr + x); };
105
gnash::Network::byte_t *at(int x) { return _ptr + x; };
106
// Buffer *hex2mem(const char *str);
108
// How much room is left in the buffer past the seek pointer. This is
109
// primarily used to see if the buffer is full populated with data.
110
size_t spaceLeft() { return (_nbytes - (_seekptr - _ptr)); };
112
// debug stuff, not need for running Cygnal
115
void *init(size_t nbytes);
116
gnash::Network::byte_t *_seekptr;
117
gnash::Network::byte_t *_ptr;
119
#ifdef USE_STATS_BUFFERS
120
struct timespec _stamp; // used for timing how long data stays in the queue.
125
} // end of amf namespace
127
#endif // end of __BUFFER_H__
131
// indent-tabs-mode: t