Exemplo n.º 1
0
quint8 *MsgPackPrivate::pack_uint(quint32 i, quint8 *p, bool wr)
{
    if (i <= 127) {
        qint32 val = _msgpack_be32(i);
        if (wr) *p = *( (quint8 *)&val + 3 );
        p++;
    } else if (i <= std::numeric_limits<quint8>::max()) {
        if (wr) *p = 0xcc;
        p++;
        if (wr) *p = i;
        p++;
    } else if (i <= std::numeric_limits<quint16>::max()) {
        if (wr) *p = 0xcd;
        p++;
        if (wr) _msgpack_store16(p, i);
        p += 2;
    } else {
        if (wr) *p = 0xce;
        p++;
        if (wr) _msgpack_store32(p, i);
        p += 4;
    }

    return p;
}
Exemplo n.º 2
0
quint8 *MsgPackPrivate::pack_int(qint32 i, quint8 *p, bool wr)
{
    if (i >= -32 && i <= 127) {
        qint32 val = _msgpack_be32(i);
        if (wr) *p = *( (quint8 *)&val + 3 );
        p++;
    } else if (i >= std::numeric_limits<qint8>::min()
               && i <= std::numeric_limits<quint8>::max()) {
        if (wr) *p = i > 0 ? 0xcc : 0xd0;
        p++;
        if (wr) *p = i;
        p++;
    } else if (i >= std::numeric_limits<qint16>::min() &&
               i <= std::numeric_limits<quint16>::max()) {
        if (wr) *p = i > 0 ? 0xcd : 0xd1;
        p++;
        if (wr) _msgpack_store16(p, i);
        p += 2;
    } else {
        if (wr) *p = i > 0 ? 0xce : 0xd2;
        p++;
        if (wr) _msgpack_store32(p, i);
        p += 4;
    }

    return p;
}
Exemplo n.º 3
0
void MessagePackReader::ParseMap32()
{
    log_trace();
    unsigned length;
    if (is_.Read( reinterpret_cast<char*>(&length), 4 ) != 4)
        anyrpc_throw(AnyRpcErrorTermination, "Parsing was terminated");
    length = _msgpack_be32( length );
    ParseMap( length );
}
Exemplo n.º 4
0
void MessagePackReader::ParseInt32()
{
    log_trace();
    int value;
    if (is_.Read( reinterpret_cast<char*>(&value), 4 ) != 4)
        anyrpc_throw(AnyRpcErrorTermination, "Parsing was terminated");
    value = _msgpack_be32( value );
    handler_->Int( value );
    ResetToken();
}
Exemplo n.º 5
0
void  MessagePackReader::ParseFloat32()
{
    log_trace();
    union {
        float f;
        int i;
        char str[4];
    } value;

    if (is_.Read( value.str, 4 ) != 4)
        anyrpc_throw(AnyRpcErrorTermination, "Parsing was terminated");

    value.i = _msgpack_be32(value.i);
    handler_->Float( value.f );
    ResetToken();
}