Skip to content

Commit 7e35f3a

Browse files
committed
expose compression type (tf_ctype_t) via tf_read_file_header
Previously, decoding any header with a non-zero compression type would result in a `TF_EINVALID_COMPRESSION_TYPE` error. Since none of the compression logic applies to the header itself, this limitation was removed. `tf_read_file_header` will only return a (repurposed) `TF_EINVALID_COMPRESSION_TYPE` error when the compression type is not mapped within the library. Currently 3 values (as described in the fseq file spec) are supported: TF_COMPRESSION_NONE // 0 TF_COMPRESSION_ZSTD // 1 TF_COMPRESSION_ZLIB // 2 # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit.
1 parent 74fd4d0 commit 7e35f3a

2 files changed

Lines changed: 34 additions & 12 deletions

File tree

tinyfseq.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const char *tf_err_str(enum tf_err_t err) {
3535
case TF_EINVALID_MAGIC:
3636
return "TF_EINVALID_MAGIC (invalid magic file signature)";
3737
case TF_EINVALID_COMPRESSION_TYPE:
38-
return "TF_EINVALID_COMPRESSION_TYPE (compressed files are not supported)";
38+
return "TF_EINVALID_COMPRESSION_TYPE (unknown compression format/unmapped `tf_ctype_t` value)";
3939
case TF_EINVALID_VAR_HEADER_SIZE:
4040
return "TF_EINVALID_VAR_HEADER_SIZE (undersized `tf_var_header_t` data decoding buffer)";
4141
case TF_EINVALID_VAR_VALUE_SIZE:
@@ -50,6 +50,17 @@ const char *tf_err_str(enum tf_err_t err) {
5050
#endif
5151
}
5252

53+
static inline int tf_is_known_ctype(uint8_t b) {
54+
switch (b) {
55+
case TF_COMPRESSION_NONE:
56+
case TF_COMPRESSION_ZSTD:
57+
case TF_COMPRESSION_ZLIB:
58+
return 1;
59+
default:
60+
return 0;
61+
}
62+
}
63+
5364
enum tf_err_t tf_read_file_header(const uint8_t *bd, int bs, struct tf_file_header_t *header, uint8_t **ep) {
5465
// header structure is a fixed 32 byte size according to schema
5566
// https://github.com/Cryptkeeper/fseq-file-format#header
@@ -70,11 +81,15 @@ enum tf_err_t tf_read_file_header(const uint8_t *bd, int bs, struct tf_file_head
7081

7182
// upper 4 bits contain additional compression block count data that is ignored by tinyfseq
7283
// mask to lower 4 bits to filter only the compression type field
73-
if ((bd[20] & 0xF) != 0) {
84+
const uint8_t compressionType = bd[20] & 0xF;
85+
if (!tf_is_known_ctype(compressionType)) {
7486
return TF_EINVALID_COMPRESSION_TYPE;
7587
}
7688

77-
memcpy((unsigned char *) &header->channelRangeCount, &bd[22], 1);
89+
header->compressionType = (enum tf_ctype_t) compressionType;
90+
91+
header->channelRangeCount = bd[22];
92+
7893
memcpy((unsigned char *) &header->sequenceUid, &bd[24], 8);
7994

8095
if (ep != NULL) {

tinyfseq.h

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,23 @@ enum tf_err_t {
4848
*/
4949
const char *tf_err_str(enum tf_err_t err);
5050

51+
enum tf_ctype_t {
52+
TF_COMPRESSION_NONE,
53+
TF_COMPRESSION_ZSTD,
54+
TF_COMPRESSION_ZLIB,
55+
};
56+
5157
struct tf_file_header_t {
52-
uint16_t channelDataOffset;
53-
uint8_t minorVersion;
54-
uint8_t majorVersion;
55-
uint16_t variableDataOffset;
56-
uint32_t channelCount;
57-
uint32_t frameCount;
58-
uint8_t frameStepTimeMillis;
59-
uint8_t channelRangeCount;
60-
uint64_t sequenceUid;
58+
uint16_t channelDataOffset;
59+
uint8_t minorVersion;
60+
uint8_t majorVersion;
61+
uint16_t variableDataOffset;
62+
uint32_t channelCount;
63+
uint32_t frameCount;
64+
uint8_t frameStepTimeMillis;
65+
enum tf_ctype_t compressionType;
66+
uint8_t channelRangeCount;
67+
uint64_t sequenceUid;
6168
} __attribute__((packed));
6269

6370
/**

0 commit comments

Comments
 (0)