~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to libdrizzle/pack.c

Removed dead variable, sorted authors file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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, Inc.
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
 
#include "libdrizzle.h"
21
 
#include <libdrizzle/pack.h>
22
 
#include <drizzled/korr.h>
23
 
#include <stdint.h>
 
1
/* Copyright (C) 2000-2003 MySQL AB
 
2
 
 
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.
 
6
 
 
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.
 
11
 
 
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 */
 
15
 
 
16
#include <my_global.h>
 
17
#include <drizzle.h>
24
18
 
25
19
/* Get the length of next field. Change parameter to point at fieldstart */
26
 
uint32_t net_field_length(unsigned char **packet)
 
20
ulong STDCALL net_field_length(uchar **packet)
27
21
{
28
 
  register unsigned char *pos= (unsigned char *)*packet;
 
22
  register uchar *pos= (uchar *)*packet;
29
23
  if (*pos < 251)
30
24
  {
31
25
    (*packet)++;
32
 
    return (uint32_t) *pos;
 
26
    return (ulong) *pos;
33
27
  }
34
28
  if (*pos == 251)
35
29
  {
39
33
  if (*pos == 252)
40
34
  {
41
35
    (*packet)+=3;
42
 
    return (uint32_t) uint2korr(pos+1);
 
36
    return (ulong) uint2korr(pos+1);
43
37
  }
44
38
  if (*pos == 253)
45
39
  {
46
40
    (*packet)+=4;
47
 
    return (uint32_t) uint3korr(pos+1);
 
41
    return (ulong) uint3korr(pos+1);
48
42
  }
49
 
  (*packet)+=9;          /* Must be 254 when here */
50
 
  return (uint32_t) uint4korr(pos+1);
 
43
  (*packet)+=9;                                 /* Must be 254 when here */
 
44
  return (ulong) uint4korr(pos+1);
51
45
}
52
46
 
53
47
/* The same as above but returns int64_t */
54
 
uint64_t net_field_length_ll(unsigned char **packet)
 
48
uint64_t net_field_length_ll(uchar **packet)
55
49
{
56
 
  register unsigned char *pos= *packet;
 
50
  register uchar *pos= *packet;
57
51
  if (*pos < 251)
58
52
  {
59
53
    (*packet)++;
74
68
    (*packet)+=4;
75
69
    return (uint64_t) uint3korr(pos+1);
76
70
  }
77
 
  (*packet)+=9;          /* Must be 254 when here */
 
71
  (*packet)+=9;                                 /* Must be 254 when here */
78
72
#ifdef NO_CLIENT_LONGLONG
79
73
  return (uint64_t) uint4korr(pos+1);
80
74
#else
87
81
 
88
82
  SYNOPSIS
89
83
    net_store_length()
90
 
    pkg      Store the packed integer here
91
 
    length    integers to store
 
84
    pkg                 Store the packed integer here
 
85
    length              integers to store
92
86
 
93
87
  NOTES
94
88
    This is mostly used to store lengths of strings.
99
93
   Position in 'pkg' after the packed length
100
94
*/
101
95
 
102
 
unsigned char *net_store_length(unsigned char *packet, uint64_t length)
 
96
uchar *net_store_length(uchar *packet, uint64_t length)
103
97
{
104
98
  if (length < (uint64_t) 251LL)
105
99
  {
106
 
    *packet=(unsigned char) length;
 
100
    *packet=(uchar) length;
107
101
    return packet+1;
108
102
  }
109
103
  /* 251 is reserved for NULL */
110
104
  if (length < (uint64_t) 65536LL)
111
105
  {
112
106
    *packet++=252;
113
 
    int2store(packet,(uint32_t) length);
 
107
    int2store(packet,(uint) length);
114
108
    return packet+2;
115
109
  }
116
110
  if (length < (uint64_t) 16777216LL)
117
111
  {
118
112
    *packet++=253;
119
 
    int3store(packet,(uint32_t) length);
 
113
    int3store(packet,(ulong) length);
120
114
    return packet+3;
121
115
  }
122
116
  *packet++=254;