1 #ifndef LIGHTNING_WIRE_WIRE_IO_H
2 #define LIGHTNING_WIRE_WIRE_IO_H
3 #include "config.h"
4 #include <ccan/endian/endian.h>
5 #include <ccan/io/io.h>
6 #include <ccan/short_types/short_types.h>
7 
8 /* We don't allow > 128M msgs: enough for more than 1M channels in gossip_getchannels_entry. */
9 #define WIRE_LEN_LIMIT (1 << 27)
10 
11 typedef be32 wire_len_t;
12 #define wirelen_to_cpu be32_to_cpu
13 #define cpu_to_wirelen cpu_to_be32
14 
15 /* Read message into *data, allocating off ctx. */
16 struct io_plan *io_read_wire_(struct io_conn *conn,
17 			      const tal_t *ctx,
18 			      u8 **data,
19 			      struct io_plan *(*next)(struct io_conn *, void *),
20 			      void *next_arg);
21 
22 #define io_read_wire(conn, ctx, data, next, arg)			\
23 	io_read_wire_((conn), (ctx), (data),				\
24 		      typesafe_cb_preargs(struct io_plan *, void *,	\
25 					  (next), (arg), struct io_conn *), \
26 		      (arg))
27 
28 /* Write message from data (tal_count(data) gives length).  data can be take() */
29 struct io_plan *io_write_wire_(struct io_conn *conn,
30 			       const u8 *data,
31 			       struct io_plan *(*next)(struct io_conn *, void *),
32 			       void *next_arg);
33 
34 #define io_write_wire(conn, data, next, arg)				\
35 	io_write_wire_((conn), (data),					\
36 		       typesafe_cb_preargs(struct io_plan *, void *,	\
37 					   (next), (arg), struct io_conn *), \
38 		       (arg))
39 #endif /* LIGHTNING_WIRE_WIRE_IO_H */
40