1 
2 #include "upb/pb/varint.int.h"
3 
4 /* Index is descriptor type. */
5 const uint8_t upb_pb_native_wire_types[] = {
6   UPB_WIRE_TYPE_END_GROUP,     /* ENDGROUP */
7   UPB_WIRE_TYPE_64BIT,         /* DOUBLE */
8   UPB_WIRE_TYPE_32BIT,         /* FLOAT */
9   UPB_WIRE_TYPE_VARINT,        /* INT64 */
10   UPB_WIRE_TYPE_VARINT,        /* UINT64 */
11   UPB_WIRE_TYPE_VARINT,        /* INT32 */
12   UPB_WIRE_TYPE_64BIT,         /* FIXED64 */
13   UPB_WIRE_TYPE_32BIT,         /* FIXED32 */
14   UPB_WIRE_TYPE_VARINT,        /* BOOL */
15   UPB_WIRE_TYPE_DELIMITED,     /* STRING */
16   UPB_WIRE_TYPE_START_GROUP,   /* GROUP */
17   UPB_WIRE_TYPE_DELIMITED,     /* MESSAGE */
18   UPB_WIRE_TYPE_DELIMITED,     /* BYTES */
19   UPB_WIRE_TYPE_VARINT,        /* UINT32 */
20   UPB_WIRE_TYPE_VARINT,        /* ENUM */
21   UPB_WIRE_TYPE_32BIT,         /* SFIXED32 */
22   UPB_WIRE_TYPE_64BIT,         /* SFIXED64 */
23   UPB_WIRE_TYPE_VARINT,        /* SINT32 */
24   UPB_WIRE_TYPE_VARINT,        /* SINT64 */
25 };
26 
27 /* A basic branch-based decoder, uses 32-bit values to get good performance
28  * on 32-bit architectures (but performs well on 64-bits also).
29  * This scheme comes from the original Google Protobuf implementation
30  * (proto2). */
upb_vdecode_max8_branch32(upb_decoderet r)31 upb_decoderet upb_vdecode_max8_branch32(upb_decoderet r) {
32   upb_decoderet err = {NULL, 0};
33   const char *p = r.p;
34   uint32_t low = (uint32_t)r.val;
35   uint32_t high = 0;
36   uint32_t b;
37   b = *(p++); low  |= (b & 0x7fU) << 14; if (!(b & 0x80)) goto done;
38   b = *(p++); low  |= (b & 0x7fU) << 21; if (!(b & 0x80)) goto done;
39   b = *(p++); low  |= (b & 0x7fU) << 28;
40               high  = (b & 0x7fU) >>  4; if (!(b & 0x80)) goto done;
41   b = *(p++); high |= (b & 0x7fU) <<  3; if (!(b & 0x80)) goto done;
42   b = *(p++); high |= (b & 0x7fU) << 10; if (!(b & 0x80)) goto done;
43   b = *(p++); high |= (b & 0x7fU) << 17; if (!(b & 0x80)) goto done;
44   b = *(p++); high |= (b & 0x7fU) << 24; if (!(b & 0x80)) goto done;
45   b = *(p++); high |= (b & 0x7fU) << 31; if (!(b & 0x80)) goto done;
46   return err;
47 
48 done:
49   r.val = ((uint64_t)high << 32) | low;
50   r.p = p;
51   return r;
52 }
53 
54 /* Like the previous, but uses 64-bit values. */
upb_vdecode_max8_branch64(upb_decoderet r)55 upb_decoderet upb_vdecode_max8_branch64(upb_decoderet r) {
56   const char *p = r.p;
57   uint64_t val = r.val;
58   uint64_t b;
59   upb_decoderet err = {NULL, 0};
60   b = *(p++); val |= (b & 0x7fU) << 14; if (!(b & 0x80)) goto done;
61   b = *(p++); val |= (b & 0x7fU) << 21; if (!(b & 0x80)) goto done;
62   b = *(p++); val |= (b & 0x7fU) << 28; if (!(b & 0x80)) goto done;
63   b = *(p++); val |= (b & 0x7fU) << 35; if (!(b & 0x80)) goto done;
64   b = *(p++); val |= (b & 0x7fU) << 42; if (!(b & 0x80)) goto done;
65   b = *(p++); val |= (b & 0x7fU) << 49; if (!(b & 0x80)) goto done;
66   b = *(p++); val |= (b & 0x7fU) << 56; if (!(b & 0x80)) goto done;
67   b = *(p++); val |= (b & 0x7fU) << 63; if (!(b & 0x80)) goto done;
68   return err;
69 
70 done:
71   r.val = val;
72   r.p = p;
73   return r;
74 }
75