1 /* Copyright (c) 2003, 2005 MySQL AB
2 Use is subject to license terms
3
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; version 2 of the License.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software
15 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
16
17 #ifndef PACKER_HPP
18 #define PACKER_HPP
19
20 #include <TransporterDefinitions.hpp>
21 #include "TransporterInternalDefinitions.hpp"
22
23 class Packer {
24 Uint32 preComputedWord1;
25 Uint32 checksumUsed; // Checksum shall be included in the message
26 Uint32 signalIdUsed; // Senders signal id shall be included in the message
27 public:
28 Packer(bool signalId, bool checksum);
29
30 Uint32 getMessageLength(const SignalHeader* header,
31 const LinearSectionPtr ptr[3]) const ;
32
33
34 Uint32 getMessageLength(const SignalHeader* header,
35 const SegmentedSectionPtr ptr[3]) const ;
36
37 void pack(Uint32 * insertPtr,
38 Uint32 prio,
39 const SignalHeader* header,
40 const Uint32* data,
41 const LinearSectionPtr ptr[3]) const ;
42
43 void pack(Uint32 * insertPtr,
44 Uint32 prio,
45 const SignalHeader* header,
46 const Uint32* data,
47 class SectionSegmentPool & thePool,
48 const SegmentedSectionPtr ptr[3]) const ;
49 };
50
51 inline
52 Uint32
getMessageLength(const SignalHeader * header,const LinearSectionPtr ptr[3]) const53 Packer::getMessageLength(const SignalHeader* header,
54 const LinearSectionPtr ptr[3]) const {
55 Uint32 tLen32 = header->theLength;
56 Uint32 no_seg = header->m_noOfSections;
57 tLen32 += checksumUsed;
58 tLen32 += signalIdUsed;
59 tLen32 += no_seg;
60
61 for(Uint32 i = 0; i<no_seg; i++){
62 tLen32 += ptr[i].sz;
63 }
64
65 return (tLen32 * 4) + sizeof(Protocol6);
66 }
67
68 inline
69 Uint32
getMessageLength(const SignalHeader * header,const SegmentedSectionPtr ptr[3]) const70 Packer::getMessageLength(const SignalHeader* header,
71 const SegmentedSectionPtr ptr[3]) const {
72 Uint32 tLen32 = header->theLength;
73 Uint32 no_seg = header->m_noOfSections;
74 tLen32 += checksumUsed;
75 tLen32 += signalIdUsed;
76 tLen32 += no_seg;
77
78 for(Uint32 i = 0; i<no_seg; i++){
79 tLen32 += ptr[i].sz;
80 }
81
82 return (tLen32 * 4) + sizeof(Protocol6);
83 }
84
85 #endif
86