6 n__network__msg_8h
gullradriel edited this page 2026-10-09 00:55:18 +02:00

include/nilorea/n_network_msg.h

Network messages , serialization tools. More...

Structures

Name
struct NETW_MSG
network message, array of char and int

Detailed Description

Network messages , serialization tools.

Author: Castagnier Mickael

Version: 1.0

Date: 10/05/2005

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#ifndef N_NETWORK_MESSAGES
#define N_NETWORK_MESSAGES

#ifdef __cplusplus
extern "C" {
#endif


#include <sys/param.h>

#include "n_str.h"
#include "n_list.h"
#include "n_3d.h"

#define NETMSG_IDENT_REQUEST 0
#define NETMSG_IDENT_REPLY_OK 1
#define NETMSG_IDENT_REPLY_NOK 2
#define NETMSG_STRING 3
#define NETMSG_POSITION 4
#define NETMSG_PING_REQUEST 5
#define NETMSG_PING_REPLY 6
#define NETMSG_GET_BOX 7
#define NETMSG_BOX 8
#define NETMSG_QUIT 9

#ifndef NETW_MSG_MAX_STRING_LENGTH
#define NETW_MSG_MAX_STRING_LENGTH (1024UL * 1024UL * 1024UL)
#endif

typedef struct NETW_MSG {
    LIST* tabint;
    LIST* tabstr;
    LIST* tabflt;
} NETW_MSG;

double double_swap(double value);
double htond(double value);
double ntohd(double value);

int create_msg(NETW_MSG** msg);
int delete_msg(NETW_MSG** msg);
void netw_msg_stats_get(long long* created, long long* deleted);

void netw_bytes_stats_get(long long* sent, long long* recv);
int empty_msg(NETW_MSG** msg);
int add_nb_to_msg(NETW_MSG* msg, double value);
int add_int_to_msg(NETW_MSG* msg, int value);
int add_nstrptr_to_msg(NETW_MSG* msg, N_STR* str);
int add_nstrdup_to_msg(NETW_MSG* msg, N_STR* str);
int add_strdup_to_msg(NETW_MSG* msg, const char* str);
int add_bytes_to_msg(NETW_MSG* msg, const void* bytes, size_t len);
int get_int_from_msg(NETW_MSG* msg, int* value);
int get_nb_from_msg(NETW_MSG* msg, double* value);
int get_nstr_from_msg(NETW_MSG* msg, N_STR** str);
int get_str_from_msg(NETW_MSG* msg, char** str);
int get_bytes_from_msg(NETW_MSG* msg, void** out_bytes, size_t* out_len);
N_STR* make_str_from_msg(NETW_MSG* msg);
NETW_MSG* make_msg_from_str(N_STR* str);

N_STR* netmsg_make_ping(int type, int id_from, int id_to, int time);
N_STR* netmsg_make_ident(int type, int id, N_STR* name, N_STR* passwd);
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);
N_STR* netmsg_make_string_msg(int id_from, int id_to, N_STR* name, N_STR* chan, N_STR* txt, int color);
N_STR* netmsg_make_quit_msg(void);

int netw_msg_get_type(N_STR* msg);

int netw_get_ident(N_STR* msg, int* type, int* ident, N_STR** name, N_STR** passwd);
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);
int netw_get_string(N_STR* msg, int* id, N_STR** name, N_STR** chan, N_STR** txt, int* color);
int netw_get_ping(N_STR* msg, int* type, int* from, int* to, int* time);
int netw_get_quit(N_STR* msg);


#ifdef __cplusplus
}
#endif

#endif /*#ifndef N_NETWORK*/