zre_log_msg(3)
==============

NAME
----
zre_log_msg - work with ZRE logging messages

SYNOPSIS
--------
----
//  Create a new zre_log_msg
CZMQ_EXPORT zre_log_msg_t *
    zre_log_msg_new (int id);

//  Destroy the zre_log_msg
CZMQ_EXPORT void
    zre_log_msg_destroy (zre_log_msg_t **self_p);

//  Parse a zre_log_msg from zmsg_t. Returns a new object, or NULL if
//  the message could not be parsed, or was NULL. If the socket type is
//  ZMQ_ROUTER, then parses the first frame as a routing_id. Destroys msg
//  and nullifies the msg refernce.
CZMQ_EXPORT zre_log_msg_t *
    zre_log_msg_decode (zmsg_t **msg_p);

//  Encode zre_log_msg into zmsg and destroy it. Returns a newly created
//  object or NULL if error. Use when not in control of sending the message.
//  If the socket_type is ZMQ_ROUTER, then stores the routing_id as the
//  first frame of the resulting message.
CZMQ_EXPORT zmsg_t *
    zre_log_msg_encode (zre_log_msg_t **self_p);

//  Receive and parse a zre_log_msg from the socket. Returns new object, 
//  or NULL if error. Will block if there's no message waiting.
CZMQ_EXPORT zre_log_msg_t *
    zre_log_msg_recv (void *input);

//  Receive and parse a zre_log_msg from the socket. Returns new object, 
//  or NULL either if there was no input waiting, or the recv was interrupted.
CZMQ_EXPORT zre_log_msg_t *
    zre_log_msg_recv_nowait (void *input);

//  Send the zre_log_msg to the output, and destroy it
CZMQ_EXPORT int
    zre_log_msg_send (zre_log_msg_t **self_p, void *output);

//  Send the zre_log_msg to the output, and do not destroy it
CZMQ_EXPORT int
    zre_log_msg_send_again (zre_log_msg_t *self, void *output);

//  Encode the LOG 
CZMQ_EXPORT zmsg_t *
    zre_log_msg_encode_log (
        byte level,
        byte event,
        uint16_t node,
        uint16_t peer,
        uint64_t time,
        const char *data);


//  Send the LOG to the output in one step
//  WARNING, this call will fail if output is of type ZMQ_ROUTER.
CZMQ_EXPORT int
    zre_log_msg_send_log (void *output,
        byte level,
        byte event,
        uint16_t node,
        uint16_t peer,
        uint64_t time,
        const char *data);
    
//  Duplicate the zre_log_msg message
CZMQ_EXPORT zre_log_msg_t *
    zre_log_msg_dup (zre_log_msg_t *self);

//  Print contents of message to stdout
CZMQ_EXPORT void
    zre_log_msg_print (zre_log_msg_t *self);

//  Get/set the message routing id
CZMQ_EXPORT zframe_t *
    zre_log_msg_routing_id (zre_log_msg_t *self);
CZMQ_EXPORT void
    zre_log_msg_set_routing_id (zre_log_msg_t *self, zframe_t *routing_id);

//  Get the zre_log_msg id and printable command
CZMQ_EXPORT int
    zre_log_msg_id (zre_log_msg_t *self);
CZMQ_EXPORT void
    zre_log_msg_set_id (zre_log_msg_t *self, int id);
CZMQ_EXPORT const char *
    zre_log_msg_command (zre_log_msg_t *self);

//  Get/set the level field
CZMQ_EXPORT byte
    zre_log_msg_level (zre_log_msg_t *self);
CZMQ_EXPORT void
    zre_log_msg_set_level (zre_log_msg_t *self, byte level);

//  Get/set the event field
CZMQ_EXPORT byte
    zre_log_msg_event (zre_log_msg_t *self);
CZMQ_EXPORT void
    zre_log_msg_set_event (zre_log_msg_t *self, byte event);

//  Get/set the node field
CZMQ_EXPORT uint16_t
    zre_log_msg_node (zre_log_msg_t *self);
CZMQ_EXPORT void
    zre_log_msg_set_node (zre_log_msg_t *self, uint16_t node);

//  Get/set the peer field
CZMQ_EXPORT uint16_t
    zre_log_msg_peer (zre_log_msg_t *self);
CZMQ_EXPORT void
    zre_log_msg_set_peer (zre_log_msg_t *self, uint16_t peer);

//  Get/set the time field
CZMQ_EXPORT uint64_t
    zre_log_msg_time (zre_log_msg_t *self);
CZMQ_EXPORT void
    zre_log_msg_set_time (zre_log_msg_t *self, uint64_t time);

//  Get/set the data field
CZMQ_EXPORT const char *
    zre_log_msg_data (zre_log_msg_t *self);
CZMQ_EXPORT void
    zre_log_msg_set_data (zre_log_msg_t *self, const char *format, ...);

//  Self test of this class
CZMQ_EXPORT int
    zre_log_msg_test (bool verbose);
----

DESCRIPTION
-----------

zre_log_msg - work with ZRE logging messages


EXAMPLE
-------
.From zre_log_msg_test method
----
    //  Simple create/destroy test
    zre_log_msg_t *self = zre_log_msg_new (0);
    assert (self);
    zre_log_msg_destroy (&self);

    //  Create pair of sockets we can send through
    zsock_t *input = zsock_new (ZMQ_ROUTER);
    assert (input);
    zsock_connect (input, "inproc://selftest-zre_log_msg");

    zsock_t *output = zsock_new (ZMQ_DEALER);
    assert (output);
    zsock_bind (output, "inproc://selftest-zre_log_msg");

    //  Encode/send/decode and verify each message type
    int instance;
    zre_log_msg_t *copy;
    self = zre_log_msg_new (ZRE_LOG_MSG_LOG);
    
    //  Check that _dup works on empty message
    copy = zre_log_msg_dup (self);
    assert (copy);
    zre_log_msg_destroy (&copy);

    zre_log_msg_set_level (self, 123);
    zre_log_msg_set_event (self, 123);
    zre_log_msg_set_node (self, 123);
    zre_log_msg_set_peer (self, 123);
    zre_log_msg_set_time (self, 123);
    zre_log_msg_set_data (self, "Life is short but Now lasts for ever");
    //  Send twice from same object
    zre_log_msg_send_again (self, output);
    zre_log_msg_send (&self, output);

    for (instance = 0; instance < 2; instance++) {
        self = zre_log_msg_recv (input);
        assert (self);
        assert (zre_log_msg_routing_id (self));
        
        assert (zre_log_msg_level (self) == 123);
        assert (zre_log_msg_event (self) == 123);
        assert (zre_log_msg_node (self) == 123);
        assert (zre_log_msg_peer (self) == 123);
        assert (zre_log_msg_time (self) == 123);
        assert (streq (zre_log_msg_data (self), "Life is short but Now lasts for ever"));
        zre_log_msg_destroy (&self);
    }

    zsock_destroy (&input);
    zsock_destroy (&output);
----

