1
/*****************************************************************************
3
Copyright (c) 2007, 2011, Oracle and/or its affiliates. All Rights Reserved.
5
This program is free software; you can redistribute it and/or modify it under
6
the terms of the GNU General Public License as published by the Free Software
7
Foundation; version 2 of the License.
9
This program is distributed in the hope that it will be useful, but WITHOUT
10
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with
14
this program; if not, write to the Free Software Foundation, Inc.,
15
51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
17
*****************************************************************************/
19
/******************************************************************//**
20
@file include/fts0vlc.ic
21
Full text variable length integer encoding/decoding.
23
Created 2007-03-27 Sunny Bains
24
*******************************************************/
26
#ifndef INNOBASE_FTS0VLC_IC
27
#define INNOBASE_FTS0VLC_IC
29
#include "fts0types.h"
31
/******************************************************************//**
32
Return length of val if it were encoded using our VLC scheme.
33
FIXME: We will need to be able encode 8 bytes value
34
@return length of value encoded, in bytes */
39
ulint val) /* in: value to encode */
43
} else if (val <= 16383) {
45
} else if (val <= 2097151) {
47
} else if (val <= 268435455) {
50
/* Possibly we should care that on 64-bit machines ulint can
51
contain values that we can't encode in 5 bytes, but
52
fts_encode_int doesn't handle them either so it doesn't much
59
/******************************************************************//**
60
Encode an integer using our VLC scheme and return the length in bytes.
61
@return length of value encoded, in bytes */
66
ulint val, /* in: value to encode */
67
byte* buf) /* in: buffer, must have enough space */
75
} else if (val <= 16383) {
76
*buf++ = (byte)(val >> 7);
77
*buf = (byte)(val & 0x7F);
80
} else if (val <= 2097151) {
81
*buf++ = (byte)(val >> 14);
82
*buf++ = (byte)((val >> 7) & 0x7F);
83
*buf = (byte)(val & 0x7F);
86
} else if (val <= 268435455) {
87
*buf++ = (byte)(val >> 21);
88
*buf++ = (byte)((val >> 14) & 0x7F);
89
*buf++ = (byte)((val >> 7) & 0x7F);
90
*buf = (byte)(val & 0x7F);
94
/* Best to keep the limitations of the 32/64 bit versions
95
identical, at least for the time being. */
96
ut_ad(val <= 4294967295u);
98
*buf++ = (byte)(val >> 28);
99
*buf++ = (byte)((val >> 21) & 0x7F);
100
*buf++ = (byte)((val >> 14) & 0x7F);
101
*buf++ = (byte)((val >> 7) & 0x7F);
102
*buf = (byte)(val & 0x7F);
107
/* High-bit on means "last byte in the encoded integer". */
113
/******************************************************************//**
114
Decode and return the integer that was encoded using our VLC scheme.
115
@return value decoded */
120
byte** ptr) /* in: ptr to decode from, this ptr is
121
incremented by the number of bytes decoded */
131
/* High-bit on means "last byte in the encoded integer". */