1 2import sys 3import re 4 5include = sys.argv[1] 6msg_basename = sys.argv[2] 7count = 1 8 9m = re.search(r'(.*\D)(\d+)$', sys.argv[2]) 10if m: 11 msg_basename = m.group(1) 12 count = int(m.group(2)) 13 14print(''' 15#include "{include}" 16 17char buf[1]; 18 19int main() {{ 20 upb_arena *arena = upb_arena_new(); 21 size_t size; 22'''.format(include=include)) 23 24def RefMessage(name): 25 print(''' 26 {{ 27 {name} *proto = {name}_parse(buf, 1, arena); 28 {name}_serialize(proto, arena, &size); 29 }} 30 '''.format(name=name)) 31 32RefMessage(msg_basename) 33 34for i in range(2, count + 1): 35 RefMessage(msg_basename + str(i)) 36 37print(''' 38 return 0; 39}''') 40