2019-07-24 01:54:21 +02:00
|
|
|
/* This file was generated by generate-wire.py */
|
2020-08-25 04:19:58 +02:00
|
|
|
/* Do not modify this file! Modify the .csv file it was generated from. */
|
2019-07-15 02:10:01 +02:00
|
|
|
|
2021-09-16 06:50:02 +02:00
|
|
|
#include <${header_filename}>
|
2019-07-21 05:04:59 +02:00
|
|
|
#include <ccan/array_size/array_size.h>
|
2019-07-15 02:10:01 +02:00
|
|
|
#include <ccan/mem/mem.h>
|
|
|
|
#include <ccan/tal/str/str.h>
|
|
|
|
#include <common/utils.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2021-09-09 04:40:01 +02:00
|
|
|
% if enum_sets:
|
2019-07-15 02:10:01 +02:00
|
|
|
void print${options.enum_name}_message(const u8 *msg)
|
|
|
|
{
|
|
|
|
switch ((enum ${options.enum_name})fromwire_peektype(msg)) {
|
|
|
|
% for msg in enum_sets[0]['set']:
|
|
|
|
case ${msg.enum_name()}:
|
|
|
|
printf("${msg.enum_name()}:\n");
|
|
|
|
printwire_${msg.name}("${msg.name}", msg);
|
|
|
|
return;
|
|
|
|
% endfor
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("UNKNOWN: %s\\n", tal_hex(msg, msg));
|
|
|
|
}
|
2021-09-09 04:40:01 +02:00
|
|
|
% endif
|
2019-07-15 02:10:01 +02:00
|
|
|
|
|
|
|
## 'component' for 'truncate check
|
|
|
|
<%def name="truncate_check(nested=False)">
|
|
|
|
if (!${ '*' if nested else '' }cursor) {
|
|
|
|
printf("**TRUNCATED**\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
</%def> \
|
|
|
|
## definition for printing field sets
|
|
|
|
<%def name="print_fieldset(fields, nested, cursor, plen)">
|
|
|
|
% for f in fields:
|
2019-07-23 23:36:55 +02:00
|
|
|
% if f.is_extension():
|
|
|
|
if (plen <= 0)
|
|
|
|
return;
|
|
|
|
printf("(${','.join(f.extension_names)}):");
|
|
|
|
% endif
|
2019-07-15 02:10:01 +02:00
|
|
|
% if f.len_field_of:
|
|
|
|
${f.type_obj.type_name()} ${f.name} = fromwire_${f.type_obj.name}(${cursor}, ${plen});${truncate_check(nested)} <% continue %> \
|
|
|
|
% endif
|
|
|
|
printf("${f.name}=");
|
2019-07-21 05:04:59 +02:00
|
|
|
% if f.type_obj.is_tlv():
|
|
|
|
printwire_tlvs(tal_fmt(NULL, "%s.${f.name}", fieldname), ${cursor}, ${plen}, print_tlvs_${f.type_obj.tlv.name}, ARRAY_SIZE(print_tlvs_${f.type_obj.tlv.name}));
|
|
|
|
% elif f.is_array() or f.is_varlen():
|
2019-07-15 02:10:01 +02:00
|
|
|
% if f.type_obj.has_array_helper():
|
2019-07-28 02:52:43 +02:00
|
|
|
printwire_${f.type_obj.name}_array(tal_fmt(NULL, "%s.${f.name}", fieldname), ${cursor}, ${plen}, ${f.size('*' + plen)});
|
2019-07-15 02:10:01 +02:00
|
|
|
% else:
|
|
|
|
printf("[");
|
2019-07-28 02:52:43 +02:00
|
|
|
% if f.is_implicit_len():
|
|
|
|
for (size_t i = 0; i < *${plen}; i++) {
|
|
|
|
% else:
|
2019-07-15 02:10:01 +02:00
|
|
|
for (size_t i = 0; i < ${f.size()}; i++) {
|
2019-07-28 02:52:43 +02:00
|
|
|
% endif
|
2021-09-09 04:40:01 +02:00
|
|
|
% if f.type_obj.is_subtype() or f.type_obj.is_varsize():
|
2019-07-23 23:37:55 +02:00
|
|
|
printf("{\n");
|
2019-07-21 05:04:59 +02:00
|
|
|
printwire_${f.type_obj.name}(tal_fmt(NULL, "%s.${f.name}", fieldname), ${cursor}, ${plen});
|
2019-07-23 23:37:55 +02:00
|
|
|
printf("}\n");
|
2019-07-21 05:04:59 +02:00
|
|
|
% else:
|
2019-07-15 02:10:01 +02:00
|
|
|
${f.type_obj.type_name()} v;
|
2019-07-21 05:04:59 +02:00
|
|
|
% if f.type_obj.is_assignable():
|
2019-07-15 02:10:01 +02:00
|
|
|
v = fromwire_${f.type_obj.name}(${cursor}, ${plen});
|
2019-07-21 05:04:59 +02:00
|
|
|
% else:
|
2019-07-15 02:10:01 +02:00
|
|
|
fromwire_${f.type_obj.name}(${cursor}, ${plen}, &v);
|
2019-07-21 05:04:59 +02:00
|
|
|
% endif
|
|
|
|
if (!*cursor) {
|
|
|
|
printf("**TRUNCATED**\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
<% typename = f.type_obj.name if not f.type_obj.is_truncated() else f.type_obj.name[1:] %>\
|
|
|
|
printwire_${typename}(tal_fmt(NULL, "%s.${f.name}", fieldname), &v);
|
2019-07-15 02:10:01 +02:00
|
|
|
% endif
|
|
|
|
}
|
|
|
|
printf("]");
|
|
|
|
% endif
|
|
|
|
${truncate_check(nested)} \
|
2021-09-09 04:40:01 +02:00
|
|
|
% elif f.type_obj.is_subtype() or f.type_obj.is_varsize():
|
2019-07-23 23:37:55 +02:00
|
|
|
printf("{\n");
|
2019-07-21 05:04:59 +02:00
|
|
|
printwire_${f.type_obj.name}(tal_fmt(NULL, "%s.${f.name}", fieldname), ${cursor}, ${plen});
|
2019-07-23 23:37:55 +02:00
|
|
|
printf("}\n");
|
2019-07-15 02:10:01 +02:00
|
|
|
% else:
|
|
|
|
% if f.type_obj.is_assignable():
|
|
|
|
${f.type_obj.type_name()} ${f.name} = fromwire_${f.type_obj.name}(${cursor}, ${plen});
|
|
|
|
% else:
|
|
|
|
${f.type_obj.type_name()} ${f.name};
|
|
|
|
fromwire_${f.type_obj.name}(${cursor}, ${plen}, &${f.name});
|
|
|
|
% endif
|
2019-07-21 05:04:59 +02:00
|
|
|
<% typename = f.type_obj.name if not f.type_obj.is_truncated() else f.type_obj.name[1:] %>
|
|
|
|
printwire_${typename}(tal_fmt(NULL, "%s.${f.name}", fieldname), &${f.name}); ${truncate_check(nested)} \
|
2019-07-15 02:10:01 +02:00
|
|
|
% endif
|
|
|
|
% endfor
|
|
|
|
</%def> \
|
|
|
|
## Definitions for 'subtypes'
|
|
|
|
% for subtype in subtypes:
|
2019-07-21 05:04:59 +02:00
|
|
|
|
2019-07-27 12:19:25 +02:00
|
|
|
<%
|
|
|
|
static = '' if options.expose_subtypes else 'static '
|
|
|
|
%>\
|
|
|
|
${static}void printwire_${subtype.name}(const char *fieldname, const u8 **cursor, size_t *plen)
|
2019-07-15 02:10:01 +02:00
|
|
|
{
|
|
|
|
${print_fieldset(subtype.fields.values(), True, 'cursor', 'plen')}
|
|
|
|
}
|
|
|
|
% endfor
|
2019-07-21 05:04:59 +02:00
|
|
|
% for tlv in tlvs.values():
|
2019-07-15 02:10:01 +02:00
|
|
|
|
2019-07-21 05:04:59 +02:00
|
|
|
% for msg in tlv.messages.values():
|
|
|
|
static void printwire_${msg.struct_name()}(const char *fieldname, const u8 **cursor, size_t *plen)
|
|
|
|
{
|
|
|
|
printf("(msg_name=%s)\n", "${msg.name}");
|
|
|
|
${print_fieldset(msg.fields.values(), True, 'cursor', 'plen')}
|
|
|
|
}
|
|
|
|
% endfor
|
|
|
|
|
|
|
|
static const struct tlv_print_record_type print_tlvs_${tlv.name}[] = {
|
|
|
|
% for msg in tlv.messages.values():
|
|
|
|
{ ${msg.number}, printwire_${msg.struct_name()} },
|
|
|
|
% endfor
|
|
|
|
};
|
|
|
|
% endfor
|
2019-07-15 02:10:01 +02:00
|
|
|
% for msg in messages:
|
|
|
|
void printwire_${msg.name}(const char *fieldname, const u8 *cursor)
|
|
|
|
{
|
|
|
|
|
|
|
|
size_t plen = tal_count(cursor);
|
|
|
|
if (fromwire_u16(&cursor, &plen) != ${msg.enum_name()}) {
|
|
|
|
printf("WRONG TYPE?!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
${print_fieldset(msg.fields.values(), False, '&cursor', '&plen')}
|
|
|
|
|
|
|
|
## Length check
|
|
|
|
if (plen != 0)
|
|
|
|
printf("EXTRA: %s\n", tal_hexstr(NULL, cursor, plen));
|
|
|
|
}
|
|
|
|
% endfor
|
2019-07-21 05:04:59 +02:00
|
|
|
|
|
|
|
% if bool(tlvs):
|
2021-09-09 04:40:01 +02:00
|
|
|
void print${options.enum_name}_tlv_message(const char *tlv_name, const u8 *msg) {
|
2020-04-07 09:03:04 +02:00
|
|
|
size_t plen = tal_count(msg);
|
2022-03-23 00:31:14 +01:00
|
|
|
% for tlv in tlvs.values():
|
|
|
|
if (strcmp(tlv_name, "${tlv.name}") == 0) {
|
|
|
|
printwire_tlvs(tlv_name, &msg, &plen, print_tlvs_${tlv.name}, ARRAY_SIZE(print_tlvs_${tlv.name}));
|
2019-07-21 05:04:59 +02:00
|
|
|
}
|
|
|
|
% endfor
|
|
|
|
}
|
2021-09-09 04:40:01 +02:00
|
|
|
% endif
|