1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include <SectionReader.hpp>
17
#include <TransporterDefinitions.hpp>
18
#include "LongSignal.hpp"
22
class SectionSegmentPool & m_pool;
23
class SectionSegment * m_head;
24
class SectionSegment * m_currentPos;
27
SectionReader::SectionReader
28
(struct SegmentedSectionPtr & ptr, class SectionSegmentPool & pool)
40
m_currentSegment = ptr.p;
45
SectionReader::reset(){
47
m_currentSegment = m_head;
51
SectionReader::step(Uint32 len){
52
if(m_pos + len >= m_len) {
56
while(len > SectionSegment::DataLength){
57
m_currentSegment = m_pool.getPtr(m_currentSegment->m_nextSegment);
59
len -= SectionSegment::DataLength;
60
m_pos += SectionSegment::DataLength;
63
Uint32 ind = m_pos % SectionSegment::DataLength;
69
if(ind == SectionSegment::DataLength){
71
m_currentSegment = m_pool.getPtr(m_currentSegment->m_nextSegment);
78
SectionReader::getWord(Uint32 * dst){
87
SectionReader::peekWord(Uint32 * dst) const {
89
Uint32 ind = m_pos % SectionSegment::DataLength;
90
* dst = m_currentSegment->theData[ind];
97
SectionReader::peekWords(Uint32 * dst, Uint32 len) const {
98
if(m_pos + len > m_len)
101
Uint32 ind = (m_pos % SectionSegment::DataLength);
102
Uint32 left = SectionSegment::DataLength - ind;
103
SectionSegment * p = m_currentSegment;
106
memcpy(dst, &p->theData[ind], 4 * left);
110
left = SectionSegment::DataLength;
111
p = m_pool.getPtr(p->m_nextSegment);
114
memcpy(dst, &p->theData[ind], 4 * len);
119
SectionReader::getWords(Uint32 * dst, Uint32 len){
120
if(m_pos + len > m_len)
123
Uint32 ind = (m_pos % SectionSegment::DataLength);
124
Uint32 left = SectionSegment::DataLength - ind;
125
SectionSegment * p = m_currentSegment;
128
memcpy(dst, &p->theData[ind], 4 * left);
132
left = SectionSegment::DataLength;
133
p = m_pool.getPtr(p->m_nextSegment);
136
memcpy(dst, &p->theData[ind], 4 * len);
139
m_currentSegment = p;