Skip to content

Commit aeb161f

Browse files
committed
v3.0.0
(Incompatible with v2.x usage, although the underlying changes are minor.) The biggest change is new function/struct names. The snakecase has been replaced to reduce long lines of code when using the library. Each struct has its name prefixing the function name, followed by _read. This makes a clean assocation between each type (e.g. `TFHeader` and `TFHeader_read`). `enum tf_err_t` -> `TFError` `tf_err_str` -> `TFError_string` `struct tf_var_header_t` -> `TFVarHeader` `tf_read_var_header` -> `TFVarHeader_read` `struct tf_file_header_t` -> `TFHeader` `tf_read_file_header` -> `TFHeader_read` ... Ignoring the new typedefs, the struct names are mostly unchanged with the exception of `struct tf_file_header_t` being shortened to `struct tf_header_t`. There were multiple errors describing undersized buffers provided to _read functions. They have been unified into a single `TF_EINVALID_BUFFER_SIZE` error value. The previously definable macro, TINYFSEQ_MEMCPY, was replaced with usage of `__builtin_memcpy`.
1 parent 4c274a8 commit aeb161f

File tree

4 files changed

+166
-227
lines changed

4 files changed

+166
-227
lines changed

.clang-format

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,22 @@
22
BasedOnStyle: LLVM
33
AccessModifierOffset: -4
44
AlignAfterOpenBracket: Align
5-
AlignConsecutiveAssignments: AcrossComments
6-
AlignConsecutiveDeclarations: AcrossComments
5+
AlignConsecutiveAssignments: Consecutive
6+
AlignConsecutiveMacros: Consecutive
77
AlignOperands: Align
88
AllowAllArgumentsOnNextLine: false
99
AllowAllConstructorInitializersOnNextLine: false
1010
AllowAllParametersOfDeclarationOnNextLine: false
1111
AllowShortBlocksOnASingleLine: Always
1212
AllowShortCaseLabelsOnASingleLine: false
13-
AllowShortFunctionsOnASingleLine: All
14-
AllowShortIfStatementsOnASingleLine: Never
13+
AllowShortFunctionsOnASingleLine: None
14+
AllowShortIfStatementsOnASingleLine: Always
1515
AllowShortLambdasOnASingleLine: All
1616
AllowShortLoopsOnASingleLine: true
1717
AlwaysBreakAfterReturnType: None
1818
AlwaysBreakTemplateDeclarations: Yes
19+
BinPackArguments: true
20+
BinPackParameters: false
1921
BreakBeforeBraces: Custom
2022
BraceWrapping:
2123
AfterCaseLabel: false
@@ -34,7 +36,7 @@ BreakBeforeBinaryOperators: None
3436
BreakBeforeTernaryOperators: true
3537
BreakConstructorInitializers: BeforeColon
3638
BreakInheritanceList: BeforeColon
37-
ColumnLimit: 0
39+
ColumnLimit: 80
3840
CompactNamespaces: false
3941
ContinuationIndentWidth: 8
4042
IndentCaseLabels: true

README.md

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,15 @@
11
# libtinyfseq
22

3-
A single-file library (~150 LOC) for decoding FSEQ (.fseq) v2.0+ sequence files developed and popularized by
4-
the [fpp](https://github.com/FalconChristmas/fpp) and [xLights](https://github.com/smeighan/xLights) programs.
5-
Additional documentation for the file format is available
6-
at [Cryptkeeper/fseq-file-format](https://github.com/Cryptkeeper/fseq-file-format).
3+
A single-file library (~150 LOC) for decoding FSEQ (.fseq) v2.0+ sequence files developed and popularized by the [fpp](https://github.com/FalconChristmas/fpp) and [xLights](https://github.com/smeighan/xLights) programs. Additional documentation for the file format is available at [Cryptkeeper/fseq-file-format](https://github.com/Cryptkeeper/fseq-file-format).
74

85
## Installation
96

107
- Download and copy `tinyfseq.h` into your project locally, or to your toolchain's include paths
118
- `#include "tinyfseq.h"` as expected (you may need to modify the path).
12-
- Define `TINYFSEQ_IMPLEMENTATION` in a single C/C++ source code
13-
file ([more info on using single-file libraries](https://github.com/nothings/stb#how-do-i-use-these-libraries))
9+
- Define `TINYFSEQ_IMPLEMENTATION` in a single C/C++ source code file ([more info on using single-file libraries](https://github.com/nothings/stb#how-do-i-use-these-libraries))
1410

1511
A short example of including libtinyfseq and decoding a file header is available in [`example.c`](example.c)
1612

17-
## Library Configuration
18-
19-
Prior to including `tinyfseq.h`, two definition based options are available:
20-
21-
1. `TINYFSEQ_MEMCPY` allows you to override the selected `memcpy` function with whatever is best for your platform (
22-
currently a basic freestanding implementation, `tf_memcpy_impl`)
23-
2. `TINYFSEQ_STRIP_ERR_STRINGS` replaces all literal strings returned by `tf_err_str` with `"NULL"` (as a string) to
24-
reduce the compiled binary size
25-
2613
## Compatibility
2714

2815
- libtinyfseq uses `stdint.h` for fixed-size int types
@@ -31,19 +18,16 @@ Prior to including `tinyfseq.h`, two definition based options are available:
3118

3219
## Usage
3320

34-
libtinyfseq only defines three functions for reading the various components of a FSEQ file. See [tinyfseq.h](tinyfseq.h)
35-
for comments describing their usage.
36-
37-
| Function | Schema |
38-
| ----------------------- | ------------------------------------------------------------ |
39-
| `tf_read_file_header` | https://github.com/Cryptkeeper/fseq-file-format#header |
40-
| `tf_read_var_header` | https://github.com/Cryptkeeper/fseq-file-format#variable |
41-
| `tf_read_channel_range` | https://github.com/Cryptkeeper/fseq-file-format#sparse-range |
21+
libtinyfseq provides decoding functions for the following components of a FSEQ file. See [tinyfseq.h](tinyfseq.h) for comments describing their specific usage.
4222

43-
Two additional utility functions are provided:
23+
| Function | Schema | Type |
24+
| ------------------------- | ----------------------------------------------------------------- | -------------------- |
25+
| `TFHeader_read` | https://github.com/Cryptkeeper/fseq-file-format#header | `TFHeader` |
26+
| `TFVarHeader_read` | https://github.com/Cryptkeeper/fseq-file-format#variable | `TFVarHeader` |
27+
| `TFChannelRange_read` | https://github.com/Cryptkeeper/fseq-file-format#sparse-range | `TFChannelRange` |
28+
| `TFCompressionBlock_read` | https://github.com/Cryptkeeper/fseq-file-format#compression-block | `TFCompressionBlock` |
4429

45-
1. `tf_sequence_duration_seconds` for calculating the duration of a given sequence in seconds
46-
2. `tf_err_str` for mapping `enum tf_err_t` values into their string names
30+
All decoding functions return a `TFError` value, with `TF_OK` indicating success. If an error occurs, the value will be non-zero. An error string can be retrieved via `TFError_string` (and should _not_ be freed by the caller).
4731

4832
## License
4933

example.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,33 @@ static uint8_t FILE_DATA[] = {
4242
'U',
4343
};
4444

45-
int main() {
45+
int main(const int argc, char **const argv) {
46+
(void) argc;
47+
(void) argv;
48+
4649
printf("using tinyfseq v%s\n", TINYFSEQ_VERSION);
4750

48-
struct tf_file_header_t header;
51+
TFHeader header;
52+
TFError err;
4953

5054
// read the "embedded" file, FILE_DATA
51-
enum tf_err_t err;
52-
if ((err = tf_read_file_header(FILE_DATA, sizeof(FILE_DATA), &header, NULL))) {
53-
return err;
55+
if ((err = TFHeader_read(FILE_DATA, sizeof(FILE_DATA), &header, NULL))) {
56+
printf("libtinyfseq error: %s\n", TFError_string(err));
57+
58+
return 1;
5459
}
5560

61+
// TODO: use header fields, read variables, etc.
62+
5663
// sequenceUid is an uint64_t that normally stores a timestamp
5764
// instead it carries an 8-byte string message
5865
// this assert call validates the decoded header prior to printing the char values
5966
assert(header.sequenceUid == 6147230170719669321);
6067

61-
int bit_idx;
62-
for (bit_idx = 0; bit_idx < 64; bit_idx += 8) {
63-
uint64_t bit_mask = ((uint64_t) 0xFFu) << bit_idx;
64-
printf("%c", (uint8_t) ((header.sequenceUid & bit_mask) >> bit_idx));
68+
for (int i = 0; i < 64; i += 8) {
69+
const uint64_t mask = (uint64_t) 0xFFu << i;
70+
71+
printf("%c", (uint8_t) ((header.sequenceUid & mask) >> i));
6572
}
6673

6774
printf("\n");

0 commit comments

Comments
 (0)