Ejemplo n.º 1
0
static inline int _unpack_int(bin_unpacker_t *packer, intmax_t *p_value)
{
    int type = bin_unpack_type(packer, (uintmax_t*)p_value);
    int sign = type & BIN_INTEGER_NEGATVIE_MASK;
    int sub_type = type & BIN_INTEGER_SUBTYPE_MASK;

    if (type < BIN_TYPE_INTEGER)
    {
        packer->error = __LINE__;
        return -1;
    }

    if (!sign)
    {
        if (*p_value < 0)
        {
            packer->error = __LINE__;
            return -1;
        }
    }
    else
    {
        *p_value = -*p_value;
        if (*p_value > 0)
        {
            packer->error = __LINE__;
            return -1;
        }
    }

    return 0;
}
Ejemplo n.º 2
0
static BINPACK_INLINE int do_unpack_int(bin_unpacker_t *packer, intmax_t *p_value)
{
    int type = bin_unpack_type(packer, (uintmax_t*)p_value);
    int sign = type & BIN_MASK_INTEGER_SIGN;

    if (type < BIN_TYPE_INTEGER)
    {
        packer->error = __LINE__;
        return -1;
    }

    if (!sign)
    {
        if (*p_value < 0)
        {
            packer->error = __LINE__;
            return -1;
        }
    }
    else
    {
        *p_value = -*p_value;
        if (*p_value > 0)
        {
            packer->error = __LINE__;
            return -1;
        }
    }

    return 0;
}
Ejemplo n.º 3
0
int bin_unpack_real_double(bin_unpacker_t *packer, double *p_value)
{
    uintmax_t num;
    if (BIN_TYPE_REAL_DOUBLE != bin_unpack_type(packer, &num))
    {
        packer->error = __LINE__;
        return -1;
    }

    *p_value = bin_make_double(packer);
    return 0;
}
Ejemplo n.º 4
0
int bin_unpack_real_float(bin_unpacker_t *packer, float *p_value)
{
    uintmax_t num;
    if (BIN_TYPE_REAL_FLOAT != bin_unpack_type(packer, &num))
    {
        packer->error = __LINE__;
        return -1;
    }

    *p_value = bin_make_float(packer);

    return 0;
}
Ejemplo n.º 5
0
int bin_unpack_float_single(bin_unpacker_t *packer, float *p_value)
{
    uintmax_t num;
    if (BIN_TYPE_FLOAT_SINGLE != bin_unpack_type(packer, &num))
    {
        packer->error = __LINE__;
        return -1;
    }

    *p_value = bin_make_float(packer);

    return 0;
}
Ejemplo n.º 6
0
static BINPACK_INLINE int do_unpack_unit(bin_unpacker_t *packer, intmax_t *p_value)
{
    uintmax_t num;

    int type = bin_unpack_type(packer, (uintmax_t*)p_value);
    int sign = type & BIN_MASK_INTEGER_SIGN;

    if (type < BIN_TYPE_INTEGER || sign)
    {
        packer->error = __LINE__;
        return -1;
    }

    *p_value = num;
    return 0;
}
Ejemplo n.º 7
0
int bin_peek_type(bin_unpacker_t *packer)
{
    uintmax_t num;
    int type;
    size_t pos = packer->pos;

    type = bin_unpack_type(packer, &num);

    if (type == BIN_TYPE_INTEGER_NEGATIVE)
        type = BIN_TYPE_INTEGER;

    if (type == BIN_TYPE_BOOL_FALSE)
        type == BIN_TYPE_BOOL;

    packer->pos = pos;
    return type;
}
Ejemplo n.º 8
0
static inline int _unpack_unit(bin_unpacker_t *packer, intmax_t *p_value)
{
    uintmax_t num;

    int type = bin_unpack_type(packer, (uintmax_t*)p_value);
    int sign = type & BIN_INTEGER_NEGATVIE_MASK;
    int sub_type = type & BIN_INTEGER_SUBTYPE_MASK;

    if (type < BIN_TYPE_INTEGER || sign)
    {
        packer->error = __LINE__;
        return -1;
    }

    *p_value = num;
    return 0;
}
Ejemplo n.º 9
0
int bin_unpack_blob(bin_unpacker_t *packer, void **p_data, size_t *p_len)
{
    uintmax_t num;

    if (BIN_TYPE_BLOB != bin_unpack_type(packer, &num) || num > SSIZE_MAX)
    {
        packer->error = __LINE__;
        return -1;
    }

    if (num > packer->size - packer->pos)
    {
        packer->error = __LINE__;
        return -1;
    }

    *p_data = packer->buf + packer->pos;
    *p_len = num;
    packer->pos += num;
    return 0;
}
Ejemplo n.º 10
0
inline int bin_unpack_lstring(bin_unpacker_t *packer, char **p_str, size_t *p_len)
{
    uintmax_t num;

    if (BIN_TYPE_STRING != bin_unpack_type(packer, &num) || num > SSIZE_MAX)
    {
        packer->error = __LINE__;
        return -1;
    }

    if (num > packer->size - packer->pos)
    {
        packer->error = __LINE__;
        return -1;
    }

    *p_str = packer->buf + packer->pos;
    *p_len = num;

    packer->pos += num;
    return 0;
}