MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Packer.hpp
1 /*
2  Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
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 St, Fifth Floor, Boston, MA 02110-1301 USA
16 */
17 
18 #ifndef PACKER_HPP
19 #define PACKER_HPP
20 
21 #include <TransporterDefinitions.hpp>
22 #include "TransporterInternalDefinitions.hpp"
23 
24 #ifdef WORDS_BIGENDIAN
25  #define MY_OWN_BYTE_ORDER 1
26 #else
27  #define MY_OWN_BYTE_ORDER 0
28 #endif
29 
30 class Packer {
31  Uint32 preComputedWord1;
32  Uint32 checksumUsed; // Checksum shall be included in the message
33  Uint32 signalIdUsed; // Senders signal id shall be included in the message
34 public:
35  Packer(bool signalId, bool checksum);
36 
37  Uint32 getMessageLength(const SignalHeader* header,
38  const LinearSectionPtr ptr[3]) const ;
39 
40 
41  Uint32 getMessageLength(const SignalHeader* header,
42  const SegmentedSectionPtr ptr[3]) const ;
43 
44 
45  Uint32 getMessageLength(const SignalHeader* header,
46  const GenericSectionPtr ptr[3]) const ;
47 
48  void pack(Uint32 * insertPtr,
49  Uint32 prio,
50  const SignalHeader* header,
51  const Uint32* data,
52  const LinearSectionPtr ptr[3]) const ;
53 
54  void pack(Uint32 * insertPtr,
55  Uint32 prio,
56  const SignalHeader* header,
57  const Uint32* data,
58  class SectionSegmentPool & thePool,
59  const SegmentedSectionPtr ptr[3]) const ;
60 
61  void pack(Uint32 * insertPtr,
62  Uint32 prio,
63  const SignalHeader* header,
64  const Uint32* data,
65  const GenericSectionPtr ptr[3]) const ;
66 };
67 
68 inline
69 Uint32
70 Packer::getMessageLength(const SignalHeader* header,
71  const LinearSectionPtr 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 inline
86 Uint32
87 Packer::getMessageLength(const SignalHeader* header,
88  const SegmentedSectionPtr ptr[3]) const {
89  Uint32 tLen32 = header->theLength;
90  Uint32 no_seg = header->m_noOfSections;
91  tLen32 += checksumUsed;
92  tLen32 += signalIdUsed;
93  tLen32 += no_seg;
94 
95  for(Uint32 i = 0; i<no_seg; i++){
96  tLen32 += ptr[i].sz;
97  }
98 
99  return (tLen32 * 4) + sizeof(Protocol6);
100 }
101 
102 inline
103 Uint32
104 Packer::getMessageLength(const SignalHeader* header,
105  const GenericSectionPtr ptr[3]) const {
106  Uint32 tLen32 = header->theLength;
107  Uint32 no_seg = header->m_noOfSections;
108  tLen32 += checksumUsed;
109  tLen32 += signalIdUsed;
110  tLen32 += no_seg;
111 
112  for(Uint32 i = 0; i<no_seg; i++){
113  tLen32 += ptr[i].sz;
114  }
115 
116  return (tLen32 * 4) + sizeof(Protocol6);
117 }
118 
119 #endif