Nyx Node
Toggle main menu visibility
Loading...
Searching...
No Matches
nss.c
1
/* NyxNode
2
* Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
3
* SPDX-License-Identifier: GPL-2.0-only (Mongoose backend) or GPL-3.0+
4
*/
5
6
/*--------------------------------------------------------------------------------------------------------------------*/
7
8
#include <stdio.h>
9
#include <string.h>
10
11
#include "nyx_node_internal.h"
12
13
/*--------------------------------------------------------------------------------------------------------------------*/
14
15
void
nyx_nss_pub(
const
nyx_node_t
*node,
STR_t
device,
STR_t
stream,
size_t
n_fields,
const
uint32_t field_hashes[],
const
size_t
field_sizes[],
const
buff_t
field_buffs[])
16
{
17
if
(n_fields > 0)
18
{
19
/*------------------------------------------------------------------------------------------------------------*/
20
21
size_t
path_len = strlen(device)
22
+ 1 +
23
strlen(stream)
24
;
25
26
char
path_buff[path_len + 1];
27
28
snprintf(path_buff, path_len + 1,
"%s/%s"
, device, stream);
29
30
uint32_t path_hash =
nyx_hash
(path_len, path_buff, NYX_STREAM_MAGIC);
31
32
/*------------------------------------------------------------------------------------------------------------*/
33
34
uint32_t size = 0;
35
36
for
(
size_t
i = 0; i < n_fields; i++)
37
{
38
size += 8 + (uint32_t) field_sizes[i];
39
}
40
41
/*------------------------------------------------------------------------------------------------------------*/
42
43
uint32_t header1[3] = {
44
NYX_STREAM_MAGIC,
45
path_hash,
46
size,
47
};
48
49
internal_stream_pub(node, NYX_STR_S(buffof(header1),
sizeof
(header1)));
50
51
/*------------------------------------------------------------------------------------------------------------*/
52
53
for
(
size_t
i = 0; i < n_fields; i++)
54
{
55
uint32_t header2[2] = {
56
field_hashes[i] & 0xFFFFFFFFLU,
57
field_sizes[i] & 0xFFFFFFFFLU,
58
};
59
60
internal_stream_pub(node, NYX_STR_S(buffof(header2),
sizeof
(header2)));
61
62
internal_stream_pub(node, NYX_STR_S(field_buffs[i], field_sizes[i]));
63
}
64
65
/*------------------------------------------------------------------------------------------------------------*/
66
}
67
}
68
69
/*--------------------------------------------------------------------------------------------------------------------*/
STR_t
#define STR_t
Alias for const char *.
Definition
nyx_node.h:71
buff_t
#define buff_t
Alias for void *.
Definition
nyx_node.h:67
nyx_node_t
Opaque struct describing a Nyx node.
nyx_hash
uint32_t nyx_hash(__NYX_ZEROABLE__ size_t size, __NYX_NULLABLE__ BUFF_t buff, uint32_t seed)
Hashes a buffer using the MurmurHash2 algorithm.
Author:
Jérôme ODIER
License:
LGPL-3.0-or-later
Copyright:
LPSC / CNRS