Пример #1
0
void binary_deserialize_spec(const Object& zthis, PHPInputTransport& transport,
                             const Array& spec) {
  // SET and LIST have 'elem' => array('type', [optional] 'class')
  // MAP has 'val' => array('type', [optiona] 'class')
  while (true) {
    Variant val;

    int8_t ttype = transport.readI8();
    if (ttype == T_STOP) return;
    int16_t fieldno = transport.readI16();
    if (!(val = spec.rvalAt(fieldno)).isNull()) {
      Array fieldspec = val.toArray();
      // pull the field name
      // zend hash tables use the null at the end in the length... so strlen(hash key) + 1.
      String varname = fieldspec.rvalAt(PHPTransport::s_var).toString();

      // and the type
      int8_t expected_ttype = fieldspec.rvalAt(PHPTransport::s_type).toInt64();

      if (ttypes_are_compatible(ttype, expected_ttype)) {
        Variant rv = binary_deserialize(ttype, transport, fieldspec);
        zthis->o_set(varname, rv, zthis->getClassName());
      } else {
        skip_element(ttype, transport);
      }
    } else {
      skip_element(ttype, transport);
    }
  }
}
Пример #2
0
static
void binary_deserialize_spec(zval* zthis, PHPInputTransport& transport, HashTable* spec) {
  // SET and LIST have 'elem' => array('type', [optional] 'class')
  // MAP has 'val' => array('type', [optiona] 'class')
  zend_class_entry* ce = Z_OBJCE_P(zthis);
  while (true) {
    int8_t ttype = transport.readI8();
    if (ttype == T_STOP) {
      validate_thrift_object(zthis);
      return;
    }

    int16_t fieldno = transport.readI16();
    zval* val_ptr = zend_hash_index_find(spec, fieldno);
    if (val_ptr != nullptr) {
      HashTable* fieldspec = Z_ARRVAL_P(val_ptr);
      // pull the field name
      val_ptr = zend_hash_str_find(fieldspec, "var", sizeof("var")-1);
      char* varname = Z_STRVAL_P(val_ptr);

      // and the type
      val_ptr = zend_hash_str_find(fieldspec, "type", sizeof("type")-1);
      if (Z_TYPE_P(val_ptr) != IS_LONG) convert_to_long(val_ptr);
      int8_t expected_ttype = Z_LVAL_P(val_ptr);

      if (ttypes_are_compatible(ttype, expected_ttype)) {
        zval rv;
        ZVAL_UNDEF(&rv);

        binary_deserialize(ttype, transport, &rv, fieldspec);
        zend_update_property(ce, zthis, varname, strlen(varname), &rv);

        zval_ptr_dtor(&rv);
      } else {
        skip_element(ttype, transport);
      }
    } else {
      skip_element(ttype, transport);
    }
  }
}
Пример #3
0
void binary_deserialize_spec(zval* zthis, PHPInputTransport& transport, HashTable* spec) {
    // SET and LIST have 'elem' => array('type', [optional] 'class')
    // MAP has 'val' => array('type', [optiona] 'class')
    TSRMLS_FETCH();
    zend_class_entry* ce = zend_get_class_entry(zthis TSRMLS_CC);
    while (true) {
        zval** val_ptr = NULL;

        int8_t ttype = transport.readI8();
        if (ttype == T_STOP) return;
        int16_t fieldno = transport.readI16();
        if (zend_hash_index_find(spec, fieldno, (void**)&val_ptr) == SUCCESS) {
            HashTable* fieldspec = Z_ARRVAL_PP(val_ptr);
            // pull the field name
            // zend hash tables use the null at the end in the length... so strlen(hash key) + 1.
            zend_hash_find(fieldspec, "var", 4, (void**)&val_ptr);
            char* varname = Z_STRVAL_PP(val_ptr);

            // and the type
            zend_hash_find(fieldspec, "type", 5, (void**)&val_ptr);
            if (Z_TYPE_PP(val_ptr) != IS_LONG) convert_to_long(*val_ptr);
            int8_t expected_ttype = Z_LVAL_PP(val_ptr);

            if (ttypes_are_compatible(ttype, expected_ttype)) {
                zval* rv = NULL;
                MAKE_STD_ZVAL(rv);
                binary_deserialize(ttype, transport, rv, fieldspec);
                zend_update_property(ce, zthis, varname, strlen(varname), rv TSRMLS_CC);
                zval_ptr_dtor(&rv);
            } else {
                skip_element(ttype, transport);
            }
        } else {
            skip_element(ttype, transport);
        }
    }
}