static int hid_unpack_logical(tvbuff_t *tvb, int bit_offset, guint32 size, gint32 min, gint32 *val)
{
    size_t bytes_length;
    guint8 *bytes = tvb_get_bits_array(NULL, tvb, bit_offset, size, &bytes_length);

    switch (size / 8)
    {
        case 0:
        case 1:
            *val = bytes[0];
            break;

        case 2:
            *val = pletoh16(bytes);
            break;

        case 3:
            *val = pletoh24(bytes);
            break;

        case 4:
            *val = pletoh32(bytes);
            break;

        default:
            goto err;
    }

    if (min < 0)
        *val = ws_sign_ext32(*val, size);

    wmem_free(NULL, bytes);
    return 0;

err:
    wmem_free(NULL, bytes);
    return -1;
}
static int hid_unpack_logical(tvbuff_t *tvb, int bit_offset, guint32 size, gint32 min, gint32 *val)
{
    size_t bytes_length;
    guint8 *bytes = tvb_get_bits_array(NULL, tvb, bit_offset, size, &bytes_length);

    switch (size / 8)
    {
        case 0:
        case 1:
            *val = bytes[0];
            break;

        case 2:
            *val = pletoh16(bytes);
            break;

        case 3:
            *val = pletoh24(bytes);
            break;

        case 4:
            *val = pletoh32(bytes);
            break;

        default:
            goto err;
    }

    if (min < 0)
        *val = ws_sign_ext32(*val, size);

    wmem_free(NULL, bytes);
    return 0;

err:
    wmem_free(NULL, bytes);
    return -1;
}