|
|
|
@ -220,6 +220,8 @@ def put_banner(files, banner): |
|
|
|
|
all_strs = list() |
|
|
|
|
all_elems = list() |
|
|
|
|
static_userdata = {} |
|
|
|
|
# put metadata batch callouts first, to make the check of if a static metadata |
|
|
|
|
# string is a callout trivial |
|
|
|
|
for elem in METADATA_BATCH_CALLOUTS: |
|
|
|
|
if elem not in all_strs: |
|
|
|
|
all_strs.append(elem) |
|
|
|
@ -482,10 +484,7 @@ for a, b in all_elems: |
|
|
|
|
print >>C, '};' |
|
|
|
|
|
|
|
|
|
print >>H, 'typedef enum {' |
|
|
|
|
batch_keys = [str_idx(s) for s in METADATA_BATCH_CALLOUTS] |
|
|
|
|
batch_hash = perfect_hash(batch_keys, 'batch') |
|
|
|
|
ordered_callouts = sorted((batch_hash['pyfunc'](str_idx(elem)), elem) for elem in METADATA_BATCH_CALLOUTS) |
|
|
|
|
for _, elem in ordered_callouts: |
|
|
|
|
for elem in METADATA_BATCH_CALLOUTS: |
|
|
|
|
print >>H, ' %s,' % mangle(elem, 'batch').upper() |
|
|
|
|
print >>H, ' GRPC_BATCH_CALLOUTS_COUNT' |
|
|
|
|
print >>H, '} grpc_metadata_batch_callouts_index;' |
|
|
|
@ -493,27 +492,14 @@ print >>H |
|
|
|
|
print >>H, 'typedef union {' |
|
|
|
|
print >>H, ' struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT];' |
|
|
|
|
print >>H, ' struct {' |
|
|
|
|
for _, elem in ordered_callouts: |
|
|
|
|
for elem in METADATA_BATCH_CALLOUTS: |
|
|
|
|
print >>H, ' struct grpc_linked_mdelem *%s;' % mangle(elem, '').lower() |
|
|
|
|
print >>H, ' } named;' |
|
|
|
|
print >>H, '} grpc_metadata_batch_callouts;' |
|
|
|
|
print >>H |
|
|
|
|
print >>H, 'grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice);' |
|
|
|
|
print >>H, '#define GRPC_BATCH_INDEX_OF(slice) \\' |
|
|
|
|
print >>H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)' |
|
|
|
|
print >>H |
|
|
|
|
print >>C, batch_hash['code'] |
|
|
|
|
batch_hash_to_idx = [0] * int(batch_hash['PHASHRANGE']) |
|
|
|
|
for i, elem in enumerate( METADATA_BATCH_CALLOUTS): |
|
|
|
|
batch_hash_to_idx[batch_hash['pyfunc'](str_idx(elem))] = str_idx(elem) |
|
|
|
|
print >>C, 'static const uint8_t batch_hash_to_idx[] = {%s};' % ','.join('%d' % n for n in batch_hash_to_idx) |
|
|
|
|
print >>C |
|
|
|
|
print >>C, 'grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice) {' |
|
|
|
|
print >>C, ' if (!GRPC_IS_STATIC_METADATA_STRING(slice)) return GRPC_BATCH_CALLOUTS_COUNT;' |
|
|
|
|
print >>C, ' uint32_t idx = (uint32_t)GRPC_STATIC_METADATA_INDEX(slice);' |
|
|
|
|
print >>C, ' uint32_t hash = batch_phash(idx);' |
|
|
|
|
print >>C, ' if (hash < GPR_ARRAY_SIZE(batch_hash_to_idx) && batch_hash_to_idx[hash] == idx) return (grpc_metadata_batch_callouts_index)hash;' |
|
|
|
|
print >>C, ' return GRPC_BATCH_CALLOUTS_COUNT;' |
|
|
|
|
print >>C, '}' |
|
|
|
|
print >>C |
|
|
|
|
|
|
|
|
|
print >>H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (1 << len(COMPRESSION_ALGORITHMS)) |
|
|
|
|
print >>C, 'const uint8_t grpc_static_accept_encoding_metadata[%d] = {' % (1 << len(COMPRESSION_ALGORITHMS)) |
|
|
|
|