SBR.h
Go to the documentation of this file.
1 #ifndef _SBR_H_
2 #define _SBR_H_
3 
4 #ifdef __cplusplus
5 extern "C" {
6 #endif
7 
8 #include "stdint.h"
9 #include "stdbool.h"
10 
11 #define SBR_MAX_NUM_SECTIONS (17)
12 #define SBR_SECTION_NAME_MAX_SIZE (16)
13 #define SBR_IDENTIFIER_SIZE (2)
14 
15 #define SBR_SECTION_FLAG_BOOTABLE (1 << 0)
16 #define SBR_SECTION_FLAG_IGNORE_CHECKSUM (1 << 1)
17 #define SBR_SECTION_FLAG_COMPRESSION_MASK (0x7 << 2)
18 typedef enum {
19  SBR_NO_COMPRESSION = 0U << 2,
21  SBR_COMPRESSION_GZ = 2U << 2,
22  SBR_COMPRESSION_XZ = 3U << 2,
24 
25 static const uint8_t SBR_IDENTIFIER[SBR_IDENTIFIER_SIZE] = {'B', 'R'};
26 
27 // SBR_SECTION
28 typedef struct {
30  uint32_t size;
31  uint32_t offset;
32  uint32_t checksum;
33  uint8_t type;
34  uint8_t flags;
35 } SBR_SECTION;
36 
37 
38 // RAW_SBR_SECTION
39 typedef struct {
40  uint8_t bytes[ sizeof( ((SBR_SECTION*)0)->name ) +\
41  sizeof( ((SBR_SECTION*)0)->size ) +\
42  sizeof( ((SBR_SECTION*)0)->offset ) +\
43  sizeof( ((SBR_SECTION*)0)->checksum ) +\
44  sizeof( ((SBR_SECTION*)0)->type ) +\
45  sizeof( ((SBR_SECTION*)0)->flags ) ];
47 
48 
49 // SBR structure
50 typedef struct {
51  uint8_t identifier[SBR_IDENTIFIER_SIZE];
53 } SBR;
54 
55 #define SBR_RAW_SIZE (sizeof(SBR_SECTION_RAW) * SBR_MAX_NUM_SECTIONS + SBR_IDENTIFIER_SIZE)
56 
57 int sbr_parse(const void* buffer, uint32_t size, SBR* sbr);
58 int sbr_serialize(const SBR* sbr, void* buffer, uint32_t max_size);
59 
60 uint32_t sbr_initial_checksum();
61 uint32_t sbr_compute_checksum_prev(const void* buffer, uint32_t size, uint32_t prev_checksum);
62 uint32_t sbr_compute_checksum(const void* buffer, uint32_t size);
63 
64 void sbr_section_set_name(SBR_SECTION* sbr_section, const char* name);
65 void sbr_section_set_size(SBR_SECTION* sbr_section, uint32_t size);
66 void sbr_section_set_offset(SBR_SECTION* sbr_section, uint32_t offset);
67 void sbr_section_set_checksum(SBR_SECTION* sbr_section, uint32_t checksum);
68 void sbr_section_set_type(SBR_SECTION* sbr_section, uint8_t type);
69 void sbr_section_set_bootable(SBR_SECTION* sbr_section, bool bootable);
70 void sbr_section_set_ignore_checksum(SBR_SECTION* sbr_section, bool ignore_checksum);
71 void sbr_section_set_compression(SBR_SECTION* sbr_section, SBR_COMPRESSION compression);
72 
73 bool sbr_section_get_bootable(const SBR_SECTION* sbr_section);
74 bool sbr_section_get_ignore_checksum(const SBR_SECTION* sbr_section);
75 bool sbr_section_is_valid(const SBR_SECTION* sbr_section);
77 
78 #ifdef __cplusplus
79 }
80 #endif
81 
82 #endif // _SBR_H_
SBR_SECTION::flags
uint8_t flags
Definition: SBR.h:34
SBR_MAX_NUM_SECTIONS
#define SBR_MAX_NUM_SECTIONS
Definition: SBR.h:11
SBR_SECTION
Definition: SBR.h:28
sbr_compute_checksum
uint32_t sbr_compute_checksum(const void *buffer, uint32_t size)
Definition: SBR.c:168
SBR_COMPRESSION_XZ
@ SBR_COMPRESSION_XZ
Definition: SBR.h:22
sbr_section_get_bootable
bool sbr_section_get_bootable(const SBR_SECTION *sbr_section)
Definition: SBR.c:128
sbr_section_set_size
void sbr_section_set_size(SBR_SECTION *sbr_section, uint32_t size)
Definition: SBR.c:177
sbr_section_set_compression
void sbr_section_set_compression(SBR_SECTION *sbr_section, SBR_COMPRESSION compression)
Definition: SBR.c:215
sbr_serialize
int sbr_serialize(const SBR *sbr, void *buffer, uint32_t max_size)
Definition: SBR.c:84
SBR_IDENTIFIER
static const uint8_t SBR_IDENTIFIER[SBR_IDENTIFIER_SIZE]
Definition: SBR.h:25
SBR_SECTION::offset
uint32_t offset
Definition: SBR.h:31
sbr_compute_checksum_prev
uint32_t sbr_compute_checksum_prev(const void *buffer, uint32_t size, uint32_t prev_checksum)
Definition: SBR.c:157
dai::utility::checksum
std::uint32_t checksum(const void *buffer, std::size_t size, uint32_t prevChecksum)
Definition: Checksum.cpp:6
SBR_SECTION::checksum
uint32_t checksum
Definition: SBR.h:32
SBR_SECTION::type
uint8_t type
Definition: SBR.h:33
nanorpc::core::type::buffer
std::vector< std::uint8_t > buffer
Definition: type.h:28
SBR_COMPRESSION_GZ
@ SBR_COMPRESSION_GZ
Definition: SBR.h:21
DAI_SPAN_NAMESPACE_NAME::detail::size
constexpr auto size(const C &c) -> decltype(c.size())
Definition: span.hpp:167
sbr_section_set_type
void sbr_section_set_type(SBR_SECTION *sbr_section, uint8_t type)
Definition: SBR.c:192
SBR_SECTION_NAME_MAX_SIZE
#define SBR_SECTION_NAME_MAX_SIZE
Definition: SBR.h:12
SBR_COMPRESSION_ZLIB
@ SBR_COMPRESSION_ZLIB
Definition: SBR.h:20
SBR_NO_COMPRESSION
@ SBR_NO_COMPRESSION
Definition: SBR.h:19
SBR_SECTION::size
uint32_t size
Definition: SBR.h:30
SBR_IDENTIFIER_SIZE
#define SBR_IDENTIFIER_SIZE
Definition: SBR.h:13
sbr_parse
int sbr_parse(const void *buffer, uint32_t size, SBR *sbr)
Definition: SBR.c:57
SBR
Definition: SBR.h:50
sbr_section_get_compression
SBR_COMPRESSION sbr_section_get_compression(const SBR_SECTION *sbr_section)
Definition: SBR.c:140
sbr_section_set_bootable
void sbr_section_set_bootable(SBR_SECTION *sbr_section, bool bootable)
Definition: SBR.c:197
nanorpc::core::detail::pack::meta::type
type
Definition: pack_meta.h:26
sbr_initial_checksum
uint32_t sbr_initial_checksum()
Definition: SBR.c:153
sbr_section_is_valid
bool sbr_section_is_valid(const SBR_SECTION *sbr_section)
Definition: SBR.c:145
sbr_section_set_offset
void sbr_section_set_offset(SBR_SECTION *sbr_section, uint32_t offset)
Definition: SBR.c:182
sbr_section_set_ignore_checksum
void sbr_section_set_ignore_checksum(SBR_SECTION *sbr_section, bool ignore_checksum)
Definition: SBR.c:206
sbr_section_set_name
void sbr_section_set_name(SBR_SECTION *sbr_section, const char *name)
Definition: SBR.c:172
sbr_section_set_checksum
void sbr_section_set_checksum(SBR_SECTION *sbr_section, uint32_t checksum)
Definition: SBR.c:187
SBR_SECTION_RAW
Definition: SBR.h:39
SBR_COMPRESSION
SBR_COMPRESSION
Definition: SBR.h:18
sbr_section_get_ignore_checksum
bool sbr_section_get_ignore_checksum(const SBR_SECTION *sbr_section)
Definition: SBR.c:134


depthai
Author(s): Martin Peterlin
autogenerated on Sat Mar 22 2025 02:58:19