libnexus-rv
Classes | Macros | Typedefs | Functions
msg-decoder.h File Reference
#include "msg-types.h"
#include <stddef.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
Include dependency graph for msg-decoder.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  nexusrv_hw_cfg
 NexusRV Message decoder configuration. More...
 
struct  nexusrv_msg_decoder
 NexusRV Message decoder context. More...
 

Macros

#define NEXUS_RV_MSG_MAX_BYTES   38
 

Typedefs

typedef struct nexusrv_hw_cfg nexusrv_hw_cfg
 NexusRV Message decoder configuration. More...
 
typedef struct nexusrv_msg_decoder nexusrv_msg_decoder
 NexusRV Message decoder context. More...
 

Functions

int nexusrv_hwcfg_parse (nexusrv_msg_decoder *hwcfg, const char *str)
 
ssize_t nexusrv_sync_forward (const uint8_t *buffer, size_t limit)
 Sync forward for the first full Message. More...
 
ssize_t nexusrv_sync_backward (const uint8_t *buffer, size_t pos)
 Sync backward for the last full Message. More...
 
ssize_t nexusrv_msg_decode (const nexusrv_hw_cfg *hwcfg, const uint8_t *buffer, size_t limit, nexusrv_msg *msg)
 Decode the full NexusRV Message from buffer into msg. More...
 
ssize_t nexusrv_msg_decoder_next (nexusrv_msg_decoder *decoder, nexusrv_msg *msg)
 Iteratively decode the next Nexus Message from trace file. More...
 
uint8_t * nexusrv_msg_decoder_lastmsg (nexusrv_msg_decoder *decoder)
 Get the pointer to the last successfully decoded Message bytes. More...
 
void nexusrv_msg_decoder_rewind_last (nexusrv_msg_decoder *decoder)
 Rewind the decoder to the beginning of last Message. More...
 
int nexusrv_print_msg (FILE *fp, const nexusrv_msg *msg)
 Print the msg in human readable form to fp. More...
 

Macro Definition Documentation

◆ NEXUS_RV_MSG_MAX_BYTES

#define NEXUS_RV_MSG_MAX_BYTES   38

Maximum standard Message size in raw bytes

Typedef Documentation

◆ nexusrv_hw_cfg

NexusRV Message decoder configuration.

This should be set to match the HW implementation

◆ nexusrv_msg_decoder

NexusRV Message decoder context.

This should be initialized by nexusrv_msg_decoder_init before calling nexusrv_msg_next

Function Documentation

◆ nexusrv_msg_decode()

ssize_t nexusrv_msg_decode ( const nexusrv_hw_cfg hwcfg,
const uint8_t *  buffer,
size_t  limit,
nexusrv_msg msg 
)

Decode the full NexusRV Message from buffer into msg.

Parameters
[in]hwcfgMust match the HW implementation that produced the trace
bufferThe buffer that holds the Message
limitShould be set to the number of bytes in buffer
[out]msgDecoded Message
Return values
>0the number of bytes consumed (a positive integer) on a success decoding of msg
-nexus_stream_truncateif more bytes are expected from buffer
-nexus_msg_invalidif decoded msg is invalid
-nexus_msg_missing_fieldif decoded msg has missing fields

◆ nexusrv_msg_decoder_lastmsg()

uint8_t* nexusrv_msg_decoder_lastmsg ( nexusrv_msg_decoder decoder)

Get the pointer to the last successfully decoded Message bytes.

Returns the pointer to bytes of last Message. It must be called after a successful return of nexusrv_msg_decoder_next, otherwise it returns NULL

Parameters
[in]decoderThe same decoder used by nexusrv_msg_decoder_next
Returns
The pointer to the raw Message bytes

◆ nexusrv_msg_decoder_next()

ssize_t nexusrv_msg_decoder_next ( nexusrv_msg_decoder decoder,
nexusrv_msg msg 
)

Iteratively decode the next Nexus Message from trace file.

It handles buffer fill and refill transparently, and caller is hence freed from dealing with -nexus_stream_truncate.

Parameters
[in]decoderShould be initialized by nexusrv_msg_decoder_init
[out]msgDecoded Message
Return values
==0if no more Message to decode (EOF)
>0the number of bytes consumed (a positive integer) on a success decoding of msg (same as nexusrv_msg_decode)
-nexus_stream_truncateif EOF is already reached, and there's a partial Message at the end.
-nexus_stream_read_failedif read decoder.fd has failed, error can be retrieved from errno
-nexus_buffer_too_smallif the size of decoder.buffer is too small to fit a single Message
-nexus_msg_invalidif decoded msg is invalid
-nexus_msg_missing_fieldif decoded msg has missing fields

◆ nexusrv_msg_decoder_rewind_last()

void nexusrv_msg_decoder_rewind_last ( nexusrv_msg_decoder decoder)

Rewind the decoder to the beginning of last Message.

Rewind the decoder to point to the beginning of last Message, so it can be decoded again. This effectively "returns" the Message to the decoder. It does nothing if there's no previous invocation of nexusrv_msg_decoder_next, or it has already been called for the previous nexusrv_msg_decoder_next.

Parameters
[in]decoderThe same decoder used by nexusrv_msg_decoder_next

◆ nexusrv_print_msg()

int nexusrv_print_msg ( FILE *  fp,
const nexusrv_msg msg 
)

Print the msg in human readable form to fp.

Returns the total number of bytes written on success (as printf does), Or, on failure, the same return code of the first failed fprintf.

◆ nexusrv_sync_backward()

ssize_t nexusrv_sync_backward ( const uint8_t *  buffer,
size_t  pos 
)

Sync backward for the last full Message.

It stops at the byte where the preceding byte has MSEO==3

Parameters
bufferThe buffer that holds Messages
posShould be set to the current position in buffer
Return values
>0The position of the first full Message on success. The returned position can be equal to pos, which means the buffer contains a single Message, and we have just passed it.
-nexus_stream_truncateIf cannot find the beginning of the full Message in buffer

◆ nexusrv_sync_forward()

ssize_t nexusrv_sync_forward ( const uint8_t *  buffer,
size_t  limit 
)

Sync forward for the first full Message.

It stops at the byte where the preceding byte has MSEO==3

Parameters
bufferThe buffer that holds Messages
limitShould be set to the number of bytes in buffer
Return values
>0The offset to the first full Message on success. The returned offset can be equal to limit, which means the buffer contains a single Message, and we have just passed it.
-nexus_stream_truncateIf cannot find the beginning of the full Message in buffer