1 #include <ccan/cast/cast.h>
2 #include <common/onionreply.h>
3 #include <common/utils.h>
4 #include <wire/wire.h>
5
towire_onionreply(u8 ** cursor,const struct onionreply * r)6 void towire_onionreply(u8 **cursor, const struct onionreply *r)
7 {
8 towire_u16(cursor, tal_count(r->contents));
9 towire_u8_array(cursor, r->contents, tal_count(r->contents));
10 }
11
fromwire_onionreply(const tal_t * ctx,const u8 ** cursor,size_t * max)12 struct onionreply *fromwire_onionreply(const tal_t *ctx,
13 const u8 **cursor, size_t *max)
14 {
15 struct onionreply *r = tal(ctx, struct onionreply);
16 r->contents = fromwire_tal_arrn(r, cursor, max,
17 fromwire_u16(cursor, max));
18 if (!*cursor)
19 return tal_free(r);
20 return r;
21 }
22
dup_onionreply(const tal_t * ctx,const struct onionreply * r TAKES)23 struct onionreply *dup_onionreply(const tal_t *ctx,
24 const struct onionreply *r TAKES)
25 {
26 struct onionreply *n;
27
28 if (taken(r))
29 return cast_const(struct onionreply *, tal_steal(ctx, r));
30
31 n = tal(ctx, struct onionreply);
32 n->contents = tal_dup_talarr(n, u8, r->contents);
33 return n;
34 }
35
new_onionreply(const tal_t * ctx,const u8 * contents TAKES)36 struct onionreply *new_onionreply(const tal_t *ctx, const u8 *contents TAKES)
37 {
38 struct onionreply *r = tal(ctx, struct onionreply);
39 r->contents = tal_dup_talarr(r, u8, contents);
40 return r;
41 }
42