You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
3.1 KiB

  1. /*****************************************************************************
  2. Copyright (c) 1995, 2009, Innobase Oy. All Rights Reserved.
  3. This program is free software; you can redistribute it and/or modify it under
  4. the terms of the GNU General Public License as published by the Free Software
  5. Foundation; version 2 of the License.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. You should have received a copy of the GNU General Public License along with
  10. this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  11. Place, Suite 330, Boston, MA 02111-1307 USA
  12. *****************************************************************************/
  13. /******************************************************************//**
  14. @file mach/mach0data.c
  15. Utilities for converting data from the database file
  16. to the machine format.
  17. Created 11/28/1995 Heikki Tuuri
  18. ***********************************************************************/
  19. #include "mach0data.h"
  20. #ifdef UNIV_NONINL
  21. #include "mach0data.ic"
  22. #endif
  23. /*********************************************************//**
  24. Reads a ulint in a compressed form if the log record fully contains it.
  25. @return pointer to end of the stored field, NULL if not complete */
  26. UNIV_INTERN
  27. byte*
  28. mach_parse_compressed(
  29. /*==================*/
  30. byte* ptr, /*!< in: pointer to buffer from where to read */
  31. byte* end_ptr,/*!< in: pointer to end of the buffer */
  32. ulint* val) /*!< out: read value (< 2^32) */
  33. {
  34. ulint flag;
  35. ut_ad(ptr && end_ptr && val);
  36. if (ptr >= end_ptr) {
  37. return(NULL);
  38. }
  39. flag = mach_read_from_1(ptr);
  40. if (flag < 0x80UL) {
  41. *val = flag;
  42. return(ptr + 1);
  43. } else if (flag < 0xC0UL) {
  44. if (end_ptr < ptr + 2) {
  45. return(NULL);
  46. }
  47. *val = mach_read_from_2(ptr) & 0x7FFFUL;
  48. return(ptr + 2);
  49. } else if (flag < 0xE0UL) {
  50. if (end_ptr < ptr + 3) {
  51. return(NULL);
  52. }
  53. *val = mach_read_from_3(ptr) & 0x3FFFFFUL;
  54. return(ptr + 3);
  55. } else if (flag < 0xF0UL) {
  56. if (end_ptr < ptr + 4) {
  57. return(NULL);
  58. }
  59. *val = mach_read_from_4(ptr) & 0x1FFFFFFFUL;
  60. return(ptr + 4);
  61. } else {
  62. ut_ad(flag == 0xF0UL);
  63. if (end_ptr < ptr + 5) {
  64. return(NULL);
  65. }
  66. *val = mach_read_from_4(ptr + 1);
  67. return(ptr + 5);
  68. }
  69. }
  70. /*********************************************************//**
  71. Reads a dulint in a compressed form if the log record fully contains it.
  72. @return pointer to end of the stored field, NULL if not complete */
  73. UNIV_INTERN
  74. byte*
  75. mach_dulint_parse_compressed(
  76. /*=========================*/
  77. byte* ptr, /*!< in: pointer to buffer from where to read */
  78. byte* end_ptr,/*!< in: pointer to end of the buffer */
  79. dulint* val) /*!< out: read value */
  80. {
  81. ulint high;
  82. ulint low;
  83. ulint size;
  84. ut_ad(ptr && end_ptr && val);
  85. if (end_ptr < ptr + 5) {
  86. return(NULL);
  87. }
  88. high = mach_read_compressed(ptr);
  89. size = mach_get_compressed_size(high);
  90. ptr += size;
  91. if (end_ptr < ptr + 4) {
  92. return(NULL);
  93. }
  94. low = mach_read_from_4(ptr);
  95. *val = ut_dulint_create(high, low);
  96. return(ptr + 4);
  97. }