Drizzled Public API Documentation

mach0data.cc

00001 /*****************************************************************************
00002 
00003 Copyright (C) 1995, 2009, Innobase Oy. All Rights Reserved.
00004 
00005 This program is free software; you can redistribute it and/or modify it under
00006 the terms of the GNU General Public License as published by the Free Software
00007 Foundation; version 2 of the License.
00008 
00009 This program is distributed in the hope that it will be useful, but WITHOUT
00010 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
00012 
00013 You should have received a copy of the GNU General Public License along with
00014 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
00015 St, Fifth Floor, Boston, MA 02110-1301 USA
00016 
00017 *****************************************************************************/
00018 
00019 /******************************************************************/
00027 #include "mach0data.h"
00028 
00029 #ifdef UNIV_NONINL
00030 #include "mach0data.ic"
00031 #endif
00032 
00033 /*********************************************************/
00036 UNIV_INTERN
00037 byte*
00038 mach_parse_compressed(
00039 /*==================*/
00040   byte* ptr,  
00041   byte* end_ptr,
00042   ulint*  val)  
00043 {
00044   ulint flag;
00045 
00046   ut_ad(ptr && end_ptr && val);
00047 
00048   if (ptr >= end_ptr) {
00049 
00050     return(NULL);
00051   }
00052 
00053   flag = mach_read_from_1(ptr);
00054 
00055   if (flag < 0x80UL) {
00056     *val = flag;
00057     return(ptr + 1);
00058 
00059   } else if (flag < 0xC0UL) {
00060     if (end_ptr < ptr + 2) {
00061       return(NULL);
00062     }
00063 
00064     *val = mach_read_from_2(ptr) & 0x7FFFUL;
00065 
00066     return(ptr + 2);
00067 
00068   } else if (flag < 0xE0UL) {
00069     if (end_ptr < ptr + 3) {
00070       return(NULL);
00071     }
00072 
00073     *val = mach_read_from_3(ptr) & 0x3FFFFFUL;
00074 
00075     return(ptr + 3);
00076   } else if (flag < 0xF0UL) {
00077     if (end_ptr < ptr + 4) {
00078       return(NULL);
00079     }
00080 
00081     *val = mach_read_from_4(ptr) & 0x1FFFFFFFUL;
00082 
00083     return(ptr + 4);
00084   } else {
00085     ut_ad(flag == 0xF0UL);
00086 
00087     if (end_ptr < ptr + 5) {
00088       return(NULL);
00089     }
00090 
00091     *val = mach_read_from_4(ptr + 1);
00092     return(ptr + 5);
00093   }
00094 }