#include "msg-types.h"
#include <stddef.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <unistd.h>
Go to the source code of this file.
◆ NEXUS_RV_MSG_MAX_BYTES
#define NEXUS_RV_MSG_MAX_BYTES 38 |
Maximum standard Message size in raw bytes
◆ 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
◆ nexusrv_msg_decode()
Decode the full NexusRV Message from buffer
into msg
.
- Parameters
-
[in] | hwcfg | Must match the HW implementation that produced the trace |
| buffer | The buffer that holds the Message |
| limit | Should be set to the number of bytes in buffer |
[out] | msg | Decoded Message |
- Return values
-
>0 | the number of bytes consumed (a positive integer) on a success decoding of msg |
-nexus_stream_truncate | if more bytes are expected from buffer |
-nexus_msg_invalid | if decoded msg is invalid |
-nexus_msg_missing_field | if decoded msg has missing fields |
◆ nexusrv_msg_decoder_lastmsg()
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] | decoder | The same decoder used by nexusrv_msg_decoder_next |
- Returns
- The pointer to the raw Message bytes
◆ nexusrv_msg_decoder_next()
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] | decoder | Should be initialized by nexusrv_msg_decoder_init |
[out] | msg | Decoded Message |
- Return values
-
==0 | if no more Message to decode (EOF) |
>0 | the number of bytes consumed (a positive integer) on a success decoding of msg (same as nexusrv_msg_decode) |
-nexus_stream_truncate | if EOF is already reached, and there's a partial Message at the end. |
-nexus_stream_read_failed | if read decoder.fd has failed, error can be retrieved from errno |
-nexus_buffer_too_small | if the size of decoder.buffer is too small to fit a single Message |
-nexus_msg_invalid | if decoded msg is invalid |
-nexus_msg_missing_field | if decoded msg has missing fields |
◆ nexusrv_msg_decoder_rewind_last()
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] | decoder | The 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
-
buffer | The buffer that holds Messages |
pos | Should be set to the current position in buffer |
- Return values
-
>0 | The 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_truncate | If 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
-
buffer | The buffer that holds Messages |
limit | Should be set to the number of bytes in buffer |
- Return values
-
>0 | The 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_truncate | If cannot find the beginning of the full Message in buffer |