Skip to content

Commit

Permalink
add methods/fields for decoding compression block structures
Browse files Browse the repository at this point in the history
  • Loading branch information
Cryptkeeper committed May 15, 2023
1 parent 9fc13c7 commit 4c274a8
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions tinyfseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

#include <stdint.h>

#define TINYFSEQ_VERSION "2.1.0"
#define TINYFSEQ_VERSION "2.1.1"

enum tf_err_t {
TF_OK = 0,
Expand All @@ -51,6 +51,7 @@ enum tf_err_t {
TF_EINVALID_VAR_HEADER_SIZE,
TF_EINVALID_VAR_VALUE_SIZE,
TF_EINVALID_CHANNEL_RANGE_SIZE,
TF_EINVALID_COMPRESSION_BLOCK_SIZE,
};

/**
Expand All @@ -77,6 +78,7 @@ struct tf_file_header_t {
uint32_t frameCount;
uint8_t frameStepTimeMillis;
enum tf_ctype_t compressionType;
uint8_t compressionBlockCount;
uint8_t channelRangeCount;
uint64_t sequenceUid;
};
Expand All @@ -93,6 +95,13 @@ struct tf_file_header_t {
*/
enum tf_err_t tf_read_file_header(const uint8_t *bd, int bs, struct tf_file_header_t *header, uint8_t **ep);

struct tf_compression_block_t {
uint32_t firstFrameId;
uint32_t size;
};

enum tf_err_t tf_read_compression_block(const uint8_t *bd, int bs, struct tf_compression_block_t *block, uint8_t **ep);

struct tf_var_header_t {
uint16_t size;
uint8_t id[2];
Expand Down Expand Up @@ -171,6 +180,8 @@ const char *tf_err_str(enum tf_err_t err) {
return "TF_EINVALID_VAR_VALUE_SIZE (undersized variable value data decoding buffer)";
case TF_EINVALID_CHANNEL_RANGE_SIZE:
return "TF_EINVALID_CHANNEL_RANGE_SIZE (undersized `tf_channel_range_t` data decoding buffer)";
case TF_EINVALID_COMPRESSION_BLOCK_SIZE:
return "TF_EINVALID_COMPRESSION_BLOCK_SIZE (undersized `tf_compression_block_t` data decoding buffer)";
default:
return "unknown `tf_err_t` value";
}
Expand Down Expand Up @@ -219,7 +230,8 @@ enum tf_err_t tf_read_file_header(const uint8_t *bd, int bs, struct tf_file_head
return TF_EINVALID_COMPRESSION_TYPE;
}

header->compressionType = (enum tf_ctype_t) compressionType;
header->compressionType = (enum tf_ctype_t) compressionType;
header->compressionBlockCount = bd[21];

header->channelRangeCount = bd[22];
header->sequenceUid = ((uint64_t *) &bd[24])[0];
Expand All @@ -231,6 +243,23 @@ enum tf_err_t tf_read_file_header(const uint8_t *bd, int bs, struct tf_file_head
return TF_OK;
}

enum tf_err_t tf_read_compression_block(const uint8_t *bd, int bs, struct tf_compression_block_t *block, uint8_t **ep) {
const int COMPRESSION_BLOCK_SIZE = 8;

if (bs < COMPRESSION_BLOCK_SIZE) {
return TF_EINVALID_COMPRESSION_BLOCK_SIZE;
}

block->firstFrameId = ((uint32_t *) &bd[0])[0];
block->size = ((uint32_t *) &bd[4])[0];

if (ep) {
*ep = ((uint8_t *) bd) + COMPRESSION_BLOCK_SIZE;
}

return TF_OK;
}

enum tf_err_t tf_read_var_header(const uint8_t *bd, int bs, struct tf_var_header_t *varHeader, uint8_t *vd, int vs, uint8_t **ep) {
const int VAR_HEADER_SIZE = 4;

Expand Down

0 comments on commit 4c274a8

Please sign in to comment.