Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_network_msg.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
27#ifndef N_NETWORK_MESSAGES
28#define N_NETWORK_MESSAGES
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
39#include <sys/param.h>
40
41#include "n_str.h"
42#include "n_list.h"
43#include "n_3d.h"
44
46#define NETMSG_IDENT_REQUEST 0
48#define NETMSG_IDENT_REPLY_OK 1
50#define NETMSG_IDENT_REPLY_NOK 2
52#define NETMSG_STRING 3
54#define NETMSG_POSITION 4
56#define NETMSG_PING_REQUEST 5
58#define NETMSG_PING_REPLY 6
60#define NETMSG_GET_BOX 7
62#define NETMSG_BOX 8
64#define NETMSG_QUIT 9
65
68#ifndef NETW_MSG_MAX_STRING_LENGTH
69#define NETW_MSG_MAX_STRING_LENGTH (1024UL * 1024UL * 1024UL)
70#endif
71
81
83double double_swap(double value);
85double htond(double value);
87double ntohd(double value);
88
90int create_msg(NETW_MSG** msg);
92int delete_msg(NETW_MSG** msg);
95void netw_msg_stats_get(long long* created, long long* deleted);
96
101void netw_bytes_stats_get(long long* sent, long long* recv);
103int empty_msg(NETW_MSG** msg);
105int add_nb_to_msg(NETW_MSG* msg, double value);
107int add_int_to_msg(NETW_MSG* msg, int value);
109int add_nstrptr_to_msg(NETW_MSG* msg, N_STR* str);
111int add_nstrdup_to_msg(NETW_MSG* msg, N_STR* str);
113int add_strdup_to_msg(NETW_MSG* msg, const char* str);
121int add_bytes_to_msg(NETW_MSG* msg, const void* bytes, size_t len);
123int get_int_from_msg(NETW_MSG* msg, int* value);
125int get_nb_from_msg(NETW_MSG* msg, double* value);
127int get_nstr_from_msg(NETW_MSG* msg, N_STR** str);
129int get_str_from_msg(NETW_MSG* msg, char** str);
134int get_bytes_from_msg(NETW_MSG* msg, void** out_bytes, size_t* out_len);
139
141N_STR* netmsg_make_ping(int type, int id_from, int id_to, int time);
143N_STR* netmsg_make_ident(int type, int id, N_STR* name, N_STR* passwd);
145N_STR* netmsg_make_position_msg(int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp);
147N_STR* netmsg_make_string_msg(int id_from, int id_to, N_STR* name, N_STR* chan, N_STR* txt, int color);
150
152int netw_msg_get_type(N_STR* msg);
153
155int netw_get_ident(N_STR* msg, int* type, int* ident, N_STR** name, N_STR** passwd);
157int netw_get_position(N_STR* msg, int* id, double* X, double* Y, double* vx, double* vy, double* acc_x, double* acc_y, int* time_stamp);
159int netw_get_string(N_STR* msg, int* id, N_STR** name, N_STR** chan, N_STR** txt, int* color);
161int netw_get_ping(N_STR* msg, int* type, int* from, int* to, int* time);
163int netw_get_quit(N_STR* msg);
164
169#ifdef __cplusplus
170}
171#endif
172
173#endif /*#ifndef N_NETWORK*/
Structure of a generic LIST container.
Definition n_list.h:59
A box including a string and his lenght.
Definition n_str.h:61
LIST * tabflt
array of casted double value
LIST * tabstr
array of N_STR
LIST * tabint
array of int
double htond(double value)
convert host double to network byte order
int get_str_from_msg(NETW_MSG *msg, char **str)
get a char string from the message
int add_strdup_to_msg(NETW_MSG *msg, const char *str)
add a duplicate of a char string to the message
int netw_get_position(N_STR *msg, int *id, double *X, double *Y, double *vx, double *vy, double *acc_x, double *acc_y, int *time_stamp)
get position data from a network message
NETW_MSG * make_msg_from_str(N_STR *str)
deserialize a N_STR into a NETW_MSG
int empty_msg(NETW_MSG **msg)
empty a NETW_MSG object
void netw_msg_stats_get(long long *created, long long *deleted)
Read lifecycle counters.
double double_swap(double value)
swap bytes of a double value
N_STR * make_str_from_msg(NETW_MSG *msg)
serialize a NETW_MSG into a single N_STR
int netw_get_ping(N_STR *msg, int *type, int *from, int *to, int *time)
get ping data from a network message
int add_nstrptr_to_msg(NETW_MSG *msg, N_STR *str)
add a N_STR pointer to the message without copying
int get_nb_from_msg(NETW_MSG *msg, double *value)
get a float/double value from the message
int netw_get_quit(N_STR *msg)
get quit data from a network message
int create_msg(NETW_MSG **msg)
create a NETW_MSG object
N_STR * netmsg_make_position_msg(int id, double X, double Y, double vx, double vy, double acc_x, double acc_y, int time_stamp)
create a position network message
int netw_msg_get_type(N_STR *msg)
get the type of a network message.
int get_nstr_from_msg(NETW_MSG *msg, N_STR **str)
get a N_STR string from the message
N_STR * netmsg_make_ident(int type, int id, N_STR *name, N_STR *passwd)
create an identification network message
int add_nstrdup_to_msg(NETW_MSG *msg, N_STR *str)
add a duplicate of a N_STR to the message
int add_int_to_msg(NETW_MSG *msg, int value)
add an int to the message
double ntohd(double value)
convert network double to host byte order
void netw_bytes_stats_get(long long *sent, long long *recv)
Read process-wide network byte counters, sum of N_STR.written across every netw_add_msg / netw_get_ms...
int add_bytes_to_msg(NETW_MSG *msg, const void *bytes, size_t len)
add a binary blob to the message, clean API for raw payloads (e.g.
int netw_get_string(N_STR *msg, int *id, N_STR **name, N_STR **chan, N_STR **txt, int *color)
get string data from a network message
int delete_msg(NETW_MSG **msg)
delete a NETW_MSG object
int add_nb_to_msg(NETW_MSG *msg, double value)
add a float/double to the message
N_STR * netmsg_make_quit_msg(void)
create a quit network message
N_STR * netmsg_make_ping(int type, int id_from, int id_to, int time)
create a ping network message
int netw_get_ident(N_STR *msg, int *type, int *ident, N_STR **name, N_STR **passwd)
get identification data from a network message
int get_bytes_from_msg(NETW_MSG *msg, void **out_bytes, size_t *out_len)
get a binary blob from the message (counterpart of add_bytes_to_msg).
N_STR * netmsg_make_string_msg(int id_from, int id_to, N_STR *name, N_STR *chan, N_STR *txt, int color)
create a string network message
int get_int_from_msg(NETW_MSG *msg, int *value)
get an int from the message
network message, array of char and int
Simple 3D movement simulation.
List structures and definitions.
N_STR and string function declaration.