~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/serialize/binlog_encoding.h

  • Committer: Monty Taylor
  • Date: 2008-11-12 17:42:40 UTC
  • mto: This revision was merged to the branch mainline in revision 584.
  • Revision ID: monty@inaugust.com-20081112174240-l2vg9lnzbmjc3uyk
More header cleanup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#ifndef BINLOG_ENCODE_H_INCLUDED
2
 
#define BINLOG_ENCODE_H_INCLUDED
 
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2008 Sun Microsystems
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; version 2 of the License.
 
9
 *
 
10
 *  This program is distributed in the hope that it will be useful,
 
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *  GNU General Public License for more details.
 
14
 *
 
15
 *  You should have received a copy of the GNU General Public License
 
16
 *  along with this program; if not, write to the Free Software
 
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef DRIZZLED_SERIALIZE_BINLOG_ENCODING_H
 
21
#define DRIZZLED_SERIALIZE_BINLOG_ENCODING_H
3
22
 
4
23
#include <cstdlib>
5
24
#include <cassert>
6
25
#include <cstring>
7
 
#include CSTDINT_H
8
 
 
9
 
#define LENGTH_ENCODE_MAX_BYTES (sizeof(size_t) + 1)
10
 
 
11
 
using std::size_t;
 
26
#include <stdint.h>
 
27
 
 
28
#define LENGTH_ENCODE_MAX_BYTES (sizeof(std::size_t) + 1)
12
29
 
13
30
inline unsigned char *
14
31
length_encode(std::size_t length, unsigned char *buf)
48
65
}
49
66
 
50
67
inline unsigned char *
51
 
length_decode(unsigned char *buf, size_t *plen)
 
68
length_decode(unsigned char *buf, std::size_t *plen)
52
69
{
53
70
  if (*buf > 1) {
54
71
    *plen = *buf;
55
72
    return buf + 1;
56
73
  }
57
74
 
58
 
  size_t bytes= 1 << (*buf + 1);
 
75
  std::size_t bytes= 1 << (*buf + 1);
59
76
  unsigned char *ptr= buf + 1;
60
 
  size_t length= 0;
 
77
  std::size_t length= 0;
61
78
  for (unsigned int i = 0 ; i < bytes ; ++i)
62
79
    length |= *ptr++ << (8 * i);
63
80
  *plen= length;
73
90
   computed.
74
91
 
75
92
 */
76
 
inline size_t
 
93
inline std::size_t
77
94
length_decode_bytes(int peek)
78
95
{
79
96
  return (peek < 2) ? (1 << (peek + 1)) + 1 : 1;
80
97
}
81
98
 
82
 
#endif /* BINLOG_ENCODE_H_INCLUDED */
 
99
#endif /*  DRIZZLED_SERIALIZE_BINLOG_ENCODING_H */