MGE General C Library - Full Internal Documentation v1.8.4
Library of general C functions.
message.c File Reference

Message processing functions. More...

#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "internal.h"
#include <libmgec/libmgec.h>
#include <libmgec/mge-buffer.h>
#include <libmgec/mge-errno.h>
#include <libmgec/mge-memory.h>
#include <libmgec/mge-message.h>
Include dependency graph for message.c:

Functions

static struct mgemessageget_msg (struct mgebuffer *buf, struct mgemessage *msg)
 Get a message from a buffer object. More...
 
static struct mgemessagedeconstruct_msg (struct mgemessage *msg)
 Deconstruct a complete message to its individual elements. More...
 
struct mgemessagepull_msg (struct mgebuffer *buf, struct mgemessage *msg)
 Pull a message from a buffer object. More...
 
void clear_msg (struct mgemessage *msg, const char terminator, const char separator)
 Clear message struct. More...
 
void print_msg (struct mgemessage *msg)
 Print a message struct. More...
 
void print_def_msg_values (void)
 Print default values to stdout, for debugging. More...
 

Variables

static int args
 Number of arguments in the message. More...
 

Detailed Description

Message processing functions.

All message handling support functions.

Author
Copyright (C) 2017-2023 Mark Grant

Released under the GPLv3 only.
SPDX-License-Identifier: GPL-3.0-only

Version
v1.1.0 ==== 02/11/2023

Function Documentation

◆ clear_msg()

void clear_msg ( struct mgemessage msg,
const char  terminator,
const char  separator 
)

Clear message struct.

Free memory allocated to the object and initialise the fields.

Parameters
msgA message object to clear.
terminatorThe message delimitter to use.
separatorThe message element delimitter to use.

◆ deconstruct_msg()

static struct mgemessage * deconstruct_msg ( struct mgemessage msg)
static

Deconstruct a complete message to its individual elements.

mge_errno is set on error.

Parameters
msgA message object to process. Must be a complete message.
Returns
The resulting message object. NULL on error.

◆ get_msg()

static struct mgemessage * get_msg ( struct mgebuffer buf,
struct mgemessage msg 
)
static

Get a message from a buffer object.

Data from the buffer is extracted to the message struct. This could be a complete message, (terminated with the mgemessage.terminator), or a partial message. If it is an incomplete message then data will be appended to the partial message next time this function is invoked, repeating until a complete message is held in the struct. A complete message will have a NUL appended to make future string processing easier. On failure function arguments are unchanged and mge_errno will be set.

Parameters
bufA buffer object.
msgA message object.
Returns
The resulting message object or NULL on error.

◆ print_def_msg_values()

void print_def_msg_values ( void  )

Print default values to stdout, for debugging.

◆ print_msg()

void print_msg ( struct mgemessage msg)

Print a message struct.

Useful for debugging.

Parameters
msgThe message object to print to stdout.

◆ pull_msg()

struct mgemessage * pull_msg ( struct mgebuffer buf,
struct mgemessage msg 
)

Pull a message from a buffer object.

Pull = Get, trim buffer and deconstruct.

On error NULL is returned and mge_errno is set.

Parameters
bufA buffer object.
msgA message object.
Returns
The resulting message object, partial or complete, or NULL on error.

Variable Documentation

◆ args

int args
static

Number of arguments in the message.