#ifndef MSG_PROTO_H
#define MSG_PROTO_H
/**
* @param
*
* Support for simple protocols that send/recieve length-prefixed messages over a transport stream.
*
* This implementation is mostly geared towards handling a reasonable number of reasonably sized messages in a
* reasonable way. Hence,
*/
#include "transport.h"
/**
* Protocol state struct
*/
struct msg_proto;
/**
* User callbacks
*/
struct msg_proto_callbacks {
/**
* Message recieved.
*
* XXX: currently you must not call msg_proto_destroy from within this callback
*/
void (*on_msg) (struct msg_proto *proto, void *data, size_t len, void *arg);
/**
* Transport/protocol error occured in event handling.
*/
void (*on_error) (struct msg_proto *proto, const error_t *err, void *arg);
};
/**
* Create a msg_proto state using the given transport.
*
* This will install our callback handlers on the given transport.
*/
err_t msg_proto_create (struct msg_proto **proto_ptr, transport_t *transport, const struct msg_proto_callbacks *cb_tbl, void *cb_arg, error_t *err);
/**
* Send a message to the other endpoint
*/
err_t msg_proto_send (struct msg_proto *proto, const void *data, size_t len, error_t *err);
/**
* Destroy the protocol state and transport
*/
void msg_proto_destroy (struct msg_proto *proto);
#endif /* MSG_PROTO_H */