-
Notifications
You must be signed in to change notification settings - Fork 15
/
byte_packet.cpp
47 lines (39 loc) · 984 Bytes
/
byte_packet.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/** TAL-SH: Byte packet
REVISION: 2020/06/30
Copyright (C) 2018-2022 Dmitry I. Lyakh (Liakh)
Copyright (C) 2018-2022 Oak Ridge National Laboratory (UT-Battelle)
LICENSE: BSD 3-Clause **/
#include "byte_packet.h"
#include <cstdlib>
void initBytePacket(BytePacket * packet,
unsigned long long max_size)
{
packet->capacity = 0;
packet->base_addr = malloc(max_size);
if(packet->base_addr != NULL) packet->capacity = max_size;
packet->size_bytes = 0;
packet->position = 0;
return;
}
void destroyBytePacket(BytePacket * packet)
{
packet->capacity = 0;
packet->size_bytes = 0;
packet->position = 0;
free(packet->base_addr);
packet->base_addr = NULL;
return;
}
void clearBytePacket(BytePacket * packet)
{
packet->size_bytes = 0;
packet->position = 0;
return;
}
void resetBytePacket(BytePacket * packet,
unsigned long long new_position)
{
assert(new_position <= packet->size_bytes);
packet->position = new_position;
return;
}