static int bsd_global( bsd_ctx_t *ctx, bsd_data_t *x, const uint8_t *buffer, int length) { int nread; CHECK_LENGTH( 1); uint8_t opcode = buffer[0]; CHECK_DECODE( decodeInteger( ctx, x, buffer, length, &BS_GLOBAL_INTEGER)); CHECK_DECODE( decodeString( ctx, x, buffer, length, &BS_GLOBAL_STRING)); CHECK_DECODE( decodeCollection( ctx, x, buffer, length, NULL, &BS_GLOBAL_LIST)); CHECK_DECODE( decodeCollection( ctx, x, buffer, length, NULL, &BS_GLOBAL_MAP)); CHECK_DECODE( decodeClass( ctx, x, buffer, length)); if( 0x60 <= opcode && opcode <= 0x6f) { /* object (short form) */ CHECK_ERROR( bsd_object( ctx, x, opcode - 0x60)); return nread; } switch( opcode) { case BS_G_NULL: /* null */ decodeNull( ctx, x); break; case 0x01: /* boolean true */ x->kind = BSD_BOOL; x->content.boolean = 1; break; case 0x02: /* boolean false */ x->kind = BSD_BOOL; x->content.boolean = 0; break; case 0x70: /* object (long form) */ CHECK_SUBDECODE( bsd_uis( ctx, x, buffer + nread, length - nread), BSD_INT); CHECK_ERROR( bsd_object( ctx, x, x->content.i + 0x10)); break; case BS_G_FLOAT32: /* float */ CHECK_LENGTH( 5); x->kind = BSD_DOUBLE; float f; memcpy( &f, buffer + 1, sizeof(float)); ntoh( &f, sizeof(float), sendian.float_); x->content.d = f; break; case BS_G_FLOAT64: /* double */ CHECK_LENGTH( 9); x->kind = BSD_DOUBLE; memcpy( &(x->content.d), buffer + 1, sizeof(double)); ntoh( &(x->content.d), sizeof(double), sendian.double_); break; default: return bsd_error( x, BSD_EINVALID); } return nread; }
static int bsd_listmap( bsd_ctx_t *ctx, bsd_data_t *x, const uint8_t *buffer, int length) { int nread; CHECK_LENGTH( 1); uint8_t opcode = buffer[0]; CHECK_DECODE( decodeCollection( ctx, x, buffer, length, NULL, &BS_LISTMAP_LIST)); CHECK_DECODE( decodeCollection( ctx, x, buffer, length, NULL, &BS_LISTMAP_MAP)); if( 0x00 == opcode) { decodeNull( ctx, x); } else { return bsd_error( x, BSD_EINVALID); } return nread; }
void ResponseDecoder::decode(const QString& dataType, const QByteArray& data) { Q_UNUSED(dataType) decodeCollection(data); }