Skip to content

Commit

Permalink
The header will have 12 elements unconditionally (i.e. metalayers wil…
Browse files Browse the repository at this point in the history
…l always be there)
  • Loading branch information
FrancescAlted committed Aug 30, 2019
1 parent a62b5ba commit 9755813
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README_FRAME_FORMAT.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The header of a frame is encoded via `msgpack <https://msgpack.org>`_ and it fo
| | | +--[msgpack] int32
| | +---magic number, currently "b2frame"
| +------[msgpack] str with 8 elements
+---[msgpack] fixarray with X=0xB (11, no metalayers) or X=0xC (12) elements
+---[msgpack] fixarray with X=0xC (12) elements

|-18|-19|-1A|-1B|-1C|-1D|-1E|-1F|-20|-21|-22|-23|-24|-25|-26|-27|-28|-29|-2A|-2B|-2C|-2D|-2E|
| a4|_f0|_f1|_f2|_f3| d3| uncompressed_size | d3| compressed_size |
Expand All @@ -52,7 +52,7 @@ The header of a frame is encoded via `msgpack <https://msgpack.org>`_ and it fo
| +------[msgpack] int32
+---[msgpack] int32

The it follows the info about the filter pipeline. There is place for a pipeline that is 8 slots deep, and there is a reserved byte per every filter code and a possible associated meta-info::
Then it follows the info about the filter pipeline. There is place for a pipeline that is 8 slots deep, and there is a reserved byte per every filter code and another byte for a possible associated meta-info::

|-40|-41|-42|-43|-44|-45|-46|-47|-48|-49|-4A|-4B|-4C|-4D|-4E|-4F|-50|-51|
| d2| X | filter_codes | filter_meta |
Expand Down
18 changes: 3 additions & 15 deletions blosc/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ void *new_header_frame(blosc2_schunk *schunk, blosc2_frame *frame) {
uint8_t* h2 = calloc(FRAME_HEADER_MINLEN, 1);
uint8_t* h2p = h2;

// Make space for the first array
// The msgpack header starts here
*h2p = 0x90; // fixarray...
*h2p += 12; // ...with 12 elements
h2p += 1;

// Magic number
Expand Down Expand Up @@ -240,13 +242,6 @@ void *new_header_frame(blosc2_schunk *schunk, blosc2_frame *frame) {

// Now, deal with metalayers
int16_t nmetalayers = schunk->nmetalayers;
// The msgpack header will start as a fix array of 11 or 12 elements (if it has metalayers)
*h2 = 0x90;
*h2 += (nmetalayers > 0) ? FRAME_HEADER_NFIELDS_METALAYER : FRAME_HEADER_NFIELDS_NOMETALAYER;

if (nmetalayers == 0) {
goto out;
}

// Make space for the header of metalayers (array marker, size, map of offsets)
h2 = realloc(h2, (size_t)hsize + 1 + 1 + 2 + 1 + 2);
Expand Down Expand Up @@ -325,7 +320,6 @@ void *new_header_frame(blosc2_schunk *schunk, blosc2_frame *frame) {
hsize = (int32_t)(h2p - h2);
assert(hsize == current_header_len); // sanity check

out:
// Set the length of the whole header now that we know it
swap_store(h2 + FRAME_HEADER_LEN, &hsize, sizeof(hsize));

Expand Down Expand Up @@ -864,11 +858,6 @@ int frame_get_metalayers(blosc2_frame* frame, blosc2_schunk* schunk) {
fclose(fp);
}

bool has_metalayers = ((header[0] & 0xFu) == FRAME_HEADER_NFIELDS_METALAYER) ? true : false;
if (!has_metalayers) {
goto out;
}

// Get the size for the index of metalayers
uint16_t idx_size;
swap_store(&idx_size, header + FRAME_IDX_SIZE, sizeof(idx_size));
Expand Down Expand Up @@ -920,7 +909,6 @@ int frame_get_metalayers(blosc2_frame* frame, blosc2_schunk* schunk) {
metalayer->content = (uint8_t*)content;
}

out:
if (frame->sdata == NULL) {
free(header);
}
Expand Down
2 changes: 0 additions & 2 deletions blosc/frame.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@

// Other constants
#define FRAME_FILTER_PIPELINE_MAX (8) // the maximum number of filters that can be stored in header
#define FRAME_HEADER_NFIELDS_NOMETALAYER (11)
#define FRAME_HEADER_NFIELDS_METALAYER (12)
#define FRAME_TRAILER_VERSION (0U) // can be up to 127
#define FRAME_TRAILER_USERMETA_LEN_OFFSET (3) // offset to usermeta length
#define FRAME_TRAILER_USERMETA_OFFSET (7) // offset to usermeta chunk
Expand Down

0 comments on commit 9755813

Please sign in to comment.