reactor-c
C Runtime for Lingua Franca
|
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include "net_util.h"
#include "util.h"
Functions | |
void | encode_int64 (int64_t data, unsigned char *buffer) |
void | encode_int32 (int32_t data, unsigned char *buffer) |
void | encode_uint32 (uint32_t data, unsigned char *buffer) |
void | encode_uint16 (uint16_t data, unsigned char *buffer) |
int | host_is_big_endian () |
int32_t | swap_bytes_if_big_endian_int32 (int32_t src) |
uint32_t | swap_bytes_if_big_endian_uint32 (uint32_t src) |
int64_t | swap_bytes_if_big_endian_int64 (int64_t src) |
uint16_t | swap_bytes_if_big_endian_uint16 (uint16_t src) |
int32_t | extract_int32 (unsigned char *bytes) |
uint32_t | extract_uint32 (unsigned char *bytes) |
int64_t | extract_int64 (unsigned char *bytes) |
uint16_t | extract_uint16 (unsigned char *bytes) |
Copyright (c) 2020, The University of California at Berkeley.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Utility functions for a federate in a federated execution.
void encode_int32 | ( | int32_t | data, |
unsigned char * | buffer ) |
Write the specified data as a sequence of bytes starting at the specified address. This encodes the data in little-endian order (lowest order byte first). This works for int32_t.
data | The data to write. |
buffer | The location to start writing. |
void encode_int64 | ( | int64_t | data, |
unsigned char * | buffer ) |
Write the specified data as a sequence of bytes starting at the specified address. This encodes the data in little-endian order (lowest order byte first).
data | The data to write. |
buffer | The location to start writing. |
void encode_uint16 | ( | uint16_t | data, |
unsigned char * | buffer ) |
Write the specified data as a sequence of bytes starting at the specified address. This encodes the data in little-endian order (lowest order byte first).
data | The data to write. |
buffer | The location to start writing. |
void encode_uint32 | ( | uint32_t | data, |
unsigned char * | buffer ) |
Write the specified data as a sequence of bytes starting at the specified address. This encodes the data in little-endian order (lowest order byte first). This works for uint32_t.
data | The data to write. |
buffer | The location to start writing. |
int32_t extract_int32 | ( | unsigned char * | bytes | ) |
This will swap the order of the bytes if this machine is big endian.
bytes | The address of the start of the sequence of bytes. |
int64_t extract_int64 | ( | unsigned char * | bytes | ) |
This will swap the order of the bytes if this machine is big endian.
bytes | The address of the start of the sequence of bytes. |
uint16_t extract_uint16 | ( | unsigned char * | bytes | ) |
Extract an uint16_t from the specified byte sequence. This will swap the order of the bytes if this machine is big endian.
bytes | The address of the start of the sequence of bytes. |
uint32_t extract_uint32 | ( | unsigned char * | bytes | ) |
int host_is_big_endian | ( | void | ) |
Return true (1) if the host is big endian. Otherwise, return false.
int32_t swap_bytes_if_big_endian_int32 | ( | int32_t | src | ) |
If this host is little endian, then reverse the order of the bytes of the argument. Otherwise, return the argument unchanged. This can be used to convert the argument to network order (big endian) and then back again. Network transmissions, by convention, are big endian, meaning that the high-order byte is sent first. But many platforms, including my Mac, are little endian, meaning that the low-order byte is first in memory.
src | The argument to convert. |
int64_t swap_bytes_if_big_endian_int64 | ( | int64_t | src | ) |
If this host is little endian, then reverse the order of the bytes of the argument. Otherwise, return the argument unchanged. This can be used to convert the argument to network order (big endian) and then back again. Network transmissions, by convention, are big endian, meaning that the high-order byte is sent first. But many platforms, including my Mac, are little endian, meaning that the low-order byte is first in memory.
src | The argument to convert. |
uint16_t swap_bytes_if_big_endian_uint16 | ( | uint16_t | src | ) |
If this host is little endian, then reverse the order of the bytes of the argument. Otherwise, return the argument unchanged. This can be used to convert the argument to network order (big endian) and then back again. Network transmissions, by convention, are big endian, meaning that the high-order byte is sent first. But many platforms, including my Mac, are little endian, meaning that the low-order byte is first in memory.
src | The argument to convert. |
uint32_t swap_bytes_if_big_endian_uint32 | ( | uint32_t | src | ) |