From 9755813f146e166a0ed90e4025fe7b67e1c456bc Mon Sep 17 00:00:00 2001 From: Francesc Alted Date: Fri, 30 Aug 2019 08:56:07 +0200 Subject: [PATCH] The header will have 12 elements unconditionally (i.e. metalayers will always be there) --- README_FRAME_FORMAT.rst | 4 ++-- blosc/frame.c | 18 +++--------------- blosc/frame.h | 2 -- 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/README_FRAME_FORMAT.rst b/README_FRAME_FORMAT.rst index 56a065f99..e32bb4ec7 100644 --- a/README_FRAME_FORMAT.rst +++ b/README_FRAME_FORMAT.rst @@ -26,7 +26,7 @@ The header of a frame is encoded via `msgpack `_ 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 | @@ -52,7 +52,7 @@ The header of a frame is encoded via `msgpack `_ 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 | diff --git a/blosc/frame.c b/blosc/frame.c index d72df1d8f..c4510dc5d 100644 --- a/blosc/frame.c +++ b/blosc/frame.c @@ -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 @@ -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); @@ -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)); @@ -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)); @@ -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); } diff --git a/blosc/frame.h b/blosc/frame.h index 6a4f9145a..28f3192c4 100644 --- a/blosc/frame.h +++ b/blosc/frame.h @@ -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