Browse Source

tlv: Migrate tlv serialization to typesafe function

travis-debug
Christian Decker 5 years ago
committed by Rusty Russell
parent
commit
626675c83c
  1. 2
      common/sphinx.c
  2. 6
      common/test/run-sphinx.c
  3. 2
      tools/gen/impl_template
  4. 4
      wire/test/run-tlvstream.c

2
common/sphinx.c

@ -144,7 +144,7 @@ static void sphinx_add_tlv_hop(struct sphinx_path *path,
const struct tlv_tlv_payload *tlv)
{
u8 *tlvs = tal_arr(path, u8, 0);
towire_tlvs(&tlvs, tlvs_tlv_payload, TLVS_TLV_PAYLOAD_ARRAY_SIZE, tlv);
towire_tlv_payload(&tlvs, tlv);
sphinx_add_raw_hop(path, pubkey, SPHINX_TLV_PAYLOAD, tlvs);
}

6
common/test/run-sphinx.c

@ -43,12 +43,6 @@ size_t bigsize_get(const u8 *p UNNEEDED, size_t max UNNEEDED, bigsize_t *val UNN
/* Generated stub for bigsize_put */
size_t bigsize_put(u8 buf[BIGSIZE_MAX_LEN] UNNEEDED, bigsize_t v UNNEEDED)
{ fprintf(stderr, "bigsize_put called!\n"); abort(); }
/* Generated stub for towire_tlvs */
void towire_tlvs(u8 **pptr UNNEEDED,
const struct tlv_record_type types[] UNNEEDED,
size_t num_types UNNEEDED,
const void *record UNNEEDED)
{ fprintf(stderr, "towire_tlvs called!\n"); abort(); }
/* AUTOGENERATED MOCKS END */
secp256k1_context *secp256k1_ctx;

2
tools/gen/impl_template

@ -409,7 +409,7 @@ u8 *towire_${msg.name}(const tal_t *ctx${''.join([f.arg_desc_to() for f in msg.f
% endif
% endif
% elif f.type_obj.is_tlv():
towire_tlvs(&p, tlvs_${f.type_obj.tlv.name}, ARRAY_SIZE(tlvs_${f.type_obj.tlv.name}), ${f.name});
towire_${f.type_obj.tlv.name}(&p, ${f.name});
% elif f.is_optional: ## is optional?
if (!${f.name})
towire_bool(&p, false);

4
wire/test/run-tlvstream.c

@ -524,7 +524,7 @@ int main(void)
continue;
p2 = tal_arr(tmpctx, u8, 0);
towire_tlvs(&p2, tlvs_n1, TLVS_N1_ARRAY_SIZE, tlv_n1);
towire_n1(&p2, tlv_n1);
assert(memeq(p2, tal_count(p2), orig_p, tal_count(orig_p)));
}
@ -620,7 +620,7 @@ int main(void)
continue;
u8 *p2 = tal_arr(tmpctx, u8, 0);
towire_tlvs(&p2, tlvs_n1, TLVS_N1_ARRAY_SIZE, tlv_n1);
towire_n1(&p2, tlv_n1);
assert(memeq(orig_p, tal_count(orig_p),
p2, tal_count(p2)));
}

Loading…
Cancel
Save