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

decode_fast.h 5.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright (c) 2009-2021, Google LLC
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of Google LLC nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL Google LLC BE LIABLE FOR ANY DIRECT,
  20. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. // These are the specialized field parser functions for the fast parser.
  28. // Generated tables will refer to these by name.
  29. //
  30. // The function names are encoded with names like:
  31. //
  32. // // 123 4
  33. // upb_pss_1bt(); // Parse singular string, 1 byte tag.
  34. //
  35. // In position 1:
  36. // - 'p' for parse, most function use this
  37. // - 'c' for copy, for when we are copying strings instead of aliasing
  38. //
  39. // In position 2 (cardinality):
  40. // - 's' for singular, with or without hasbit
  41. // - 'o' for oneof
  42. // - 'r' for non-packed repeated
  43. // - 'p' for packed repeated
  44. //
  45. // In position 3 (type):
  46. // - 'b1' for bool
  47. // - 'v4' for 4-byte varint
  48. // - 'v8' for 8-byte varint
  49. // - 'z4' for zig-zag-encoded 4-byte varint
  50. // - 'z8' for zig-zag-encoded 8-byte varint
  51. // - 'f4' for 4-byte fixed
  52. // - 'f8' for 8-byte fixed
  53. // - 'm' for sub-message
  54. // - 's' for string (validate UTF-8)
  55. // - 'b' for bytes
  56. //
  57. // In position 4 (tag length):
  58. // - '1' for one-byte tags (field numbers 1-15)
  59. // - '2' for two-byte tags (field numbers 16-2048)
  60. #ifndef UPB_DECODE_FAST_H_
  61. #define UPB_DECODE_FAST_H_
  62. #include "upb/msg.h"
  63. struct upb_Decoder;
  64. // The fallback, generic parsing function that can handle any field type.
  65. // This just uses the regular (non-fast) parser to parse a single field.
  66. const char* fastdecode_generic(struct upb_Decoder* d, const char* ptr, upb_Message* msg, intptr_t table, uint64_t hasbits, uint64_t data);
  67. #define UPB_PARSE_PARAMS \
  68. struct upb_Decoder *d, const char *ptr, upb_Message *msg, intptr_t table, \
  69. uint64_t hasbits, uint64_t data
  70. /* primitive fields ***********************************************************/
  71. #define F(card, type, valbytes, tagbytes) \
  72. const char* upb_p##card##type##valbytes##_##tagbytes##bt(UPB_PARSE_PARAMS);
  73. #define TYPES(card, tagbytes) \
  74. F(card, b, 1, tagbytes) \
  75. F(card, v, 4, tagbytes) \
  76. F(card, v, 8, tagbytes) \
  77. F(card, z, 4, tagbytes) \
  78. F(card, z, 8, tagbytes) \
  79. F(card, f, 4, tagbytes) \
  80. F(card, f, 8, tagbytes)
  81. #define TAGBYTES(card) \
  82. TYPES(card, 1) \
  83. TYPES(card, 2)
  84. TAGBYTES(s)
  85. TAGBYTES(o)
  86. TAGBYTES(r)
  87. TAGBYTES(p)
  88. #undef F
  89. #undef TYPES
  90. #undef TAGBYTES
  91. /* string fields **************************************************************/
  92. #define F(card, tagbytes, type) \
  93. const char* upb_p##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS); \
  94. const char* upb_c##card##type##_##tagbytes##bt(UPB_PARSE_PARAMS);
  95. #define UTF8(card, tagbytes) \
  96. F(card, tagbytes, s) \
  97. F(card, tagbytes, b)
  98. #define TAGBYTES(card) \
  99. UTF8(card, 1) \
  100. UTF8(card, 2)
  101. TAGBYTES(s)
  102. TAGBYTES(o)
  103. TAGBYTES(r)
  104. #undef F
  105. #undef TAGBYTES
  106. /* sub-message fields *********************************************************/
  107. #define F(card, tagbytes, size_ceil, ceil_arg) \
  108. const char* upb_p##card##m_##tagbytes##bt_max##size_ceil##b(UPB_PARSE_PARAMS);
  109. #define SIZES(card, tagbytes) \
  110. F(card, tagbytes, 64, 64) \
  111. F(card, tagbytes, 128, 128) \
  112. F(card, tagbytes, 192, 192) \
  113. F(card, tagbytes, 256, 256) \
  114. F(card, tagbytes, max, -1)
  115. #define TAGBYTES(card) \
  116. SIZES(card, 1) \
  117. SIZES(card, 2)
  118. TAGBYTES(s)
  119. TAGBYTES(o)
  120. TAGBYTES(r)
  121. #undef TAGBYTES
  122. #undef SIZES
  123. #undef F
  124. #undef UPB_PARSE_PARAMS
  125. #endif /* UPB_DECODE_FAST_H_ */