2020-01-22 07:28:25 +01:00
|
|
|
#include <ccan/cast/cast.h>
|
|
|
|
#include <common/onionreply.h>
|
2020-05-15 12:32:43 +02:00
|
|
|
#include <common/utils.h>
|
2020-01-22 07:28:25 +01:00
|
|
|
#include <wire/wire.h>
|
|
|
|
|
|
|
|
void towire_onionreply(u8 **cursor, const struct onionreply *r)
|
|
|
|
{
|
|
|
|
towire_u16(cursor, tal_count(r->contents));
|
|
|
|
towire_u8_array(cursor, r->contents, tal_count(r->contents));
|
|
|
|
}
|
|
|
|
|
|
|
|
struct onionreply *fromwire_onionreply(const tal_t *ctx,
|
|
|
|
const u8 **cursor, size_t *max)
|
|
|
|
{
|
|
|
|
struct onionreply *r = tal(ctx, struct onionreply);
|
2020-03-04 05:13:00 +01:00
|
|
|
r->contents = fromwire_tal_arrn(r, cursor, max,
|
|
|
|
fromwire_u16(cursor, max));
|
2020-01-22 07:28:25 +01:00
|
|
|
if (!*cursor)
|
|
|
|
return tal_free(r);
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct onionreply *dup_onionreply(const tal_t *ctx,
|
|
|
|
const struct onionreply *r TAKES)
|
|
|
|
{
|
|
|
|
struct onionreply *n;
|
|
|
|
|
|
|
|
if (taken(r))
|
|
|
|
return cast_const(struct onionreply *, tal_steal(ctx, r));
|
|
|
|
|
|
|
|
n = tal(ctx, struct onionreply);
|
2020-02-27 03:17:01 +01:00
|
|
|
n->contents = tal_dup_talarr(n, u8, r->contents);
|
2020-01-22 07:28:25 +01:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct onionreply *new_onionreply(const tal_t *ctx, const u8 *contents TAKES)
|
|
|
|
{
|
|
|
|
struct onionreply *r = tal(ctx, struct onionreply);
|
2020-02-27 03:17:01 +01:00
|
|
|
r->contents = tal_dup_talarr(r, u8, contents);
|
2020-01-22 07:28:25 +01:00
|
|
|
return r;
|
|
|
|
}
|