data[data_offset + i] |= (unsigned char)((unsigned)(val >> (*buf_len - dat_len)) & (unsigned)(~((unsigned)(~0) << dat_len)));
 
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "H5Zmodule.h"          /* This source code file is part of the H5Z module */
#include "H5private.h"      /* Generic Functions            */
#include "H5Eprivate.h"     /* Error handling           */
#include "H5Iprivate.h"     /* IDs                  */
#include "H5MMprivate.h"    /* Memory management            */
#include "H5Ppublic.h"      /* Property lists           */
#include "H5Oprivate.h"         /* Object headers                       */
#include "H5Sprivate.h"     /* Dataspaces                   */
#include "H5Tprivate.h"     /* Datatypes                    */
#include "H5Zpkg.h"     /* Data filters             */
/* Struct of parameters needed for compressing/decompressing
 * one nbit atomic datatype: integer or floating-point
 */
typedef struct {
   unsigned size;         /* size of datatype */
   unsigned order;      /* datatype endianness order */
   unsigned precision;  /* datatype precision */
   unsigned offset;     /* datatype offset */
} parms_atomic;
/* Local function prototypes */
static htri_t H5Z_can_apply_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id);
static herr_t H5Z_set_local_nbit(hid_t dcpl_id, hid_t type_id, hid_t space_id);
static size_t H5Z_filter_nbit(unsigned flags, size_t cd_nelmts, const unsigned cd_values[],
                              size_t nbytes, size_t *buf_size, void **buf);
static void H5Z_calc_parms_nooptype(size_t *cd_values_actual_nparms);
static void H5Z_calc_parms_atomic(size_t *cd_values_actual_nparms);
static herr_t H5Z_calc_parms_array(const H5T_t *type, size_t *cd_values_actual_nparms);
static herr_t H5Z_calc_parms_compound(const H5T_t *type, size_t *cd_values_actual_nparms);
static herr_t H5Z_set_parms_nooptype(const H5T_t *type, unsigned *cd_values_index,
    unsigned cd_values[]);
static herr_t H5Z_set_parms_atomic(const H5T_t *type, unsigned *cd_values_index,
    unsigned cd_values[], hbool_t *need_not_compress);
static herr_t H5Z_set_parms_array(const H5T_t *type, unsigned *cd_values_index,