MCPcopy Create free account
hub / github.com/apache/thrift / binary_serialize

Function binary_serialize

lib/php/src/ext/thrift_protocol/php_thrift_protocol.cpp:694–849  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

692}
693
694static
695void binary_serialize(int8_t thrift_typeID, PHPOutputTransport& transport, zval* value, HashTable* fieldspec) {
696 if (value) {
697 ZVAL_DEREF(value);
698 }
699 // At this point the typeID (and field num, if applicable) should've already been written to the output so all we need to do is write the payload.
700 switch (thrift_typeID) {
701 case T_STOP:
702 case T_VOID:
703 return;
704 case T_STRUCT: {
705 if (Z_TYPE_P(value) != IS_OBJECT) {
706 throw_tprotocolexception("Attempt to send non-object type as a T_STRUCT", INVALID_DATA);
707 }
708 zval* spec = zend_read_static_property(Z_OBJCE_P(value), "_TSPEC", sizeof("_TSPEC")-1, true);
709 if (spec && Z_TYPE_P(spec) == IS_REFERENCE) {
710 ZVAL_DEREF(spec);
711 }
712 if (!spec || Z_TYPE_P(spec) != IS_ARRAY) {
713 throw_tprotocolexception("Attempt to send non-Thrift object as a T_STRUCT", INVALID_DATA);
714 }
715 binary_serialize_spec(value, transport, Z_ARRVAL_P(spec));
716 } return;
717 case T_BOOL:
718 if (!zval_is_bool(value)) convert_to_boolean(value);
719 transport.writeI8(Z_TYPE_INFO_P(value) == IS_TRUE ? 1 : 0);
720 return;
721 case T_BYTE:
722 if (Z_TYPE_P(value) != IS_LONG) convert_to_long(value);
723 transport.writeI8(Z_LVAL_P(value));
724 return;
725 case T_I16:
726 if (Z_TYPE_P(value) != IS_LONG) convert_to_long(value);
727 transport.writeI16(Z_LVAL_P(value));
728 return;
729 case T_I32:
730 if (Z_TYPE_P(value) != IS_LONG) convert_to_long(value);
731 transport.writeI32(Z_LVAL_P(value));
732 return;
733 case T_I64:
734 case T_U64: {
735 int64_t l_data;
736#if defined(_LP64) || defined(_WIN64)
737 if (Z_TYPE_P(value) != IS_LONG) convert_to_long(value);
738 l_data = Z_LVAL_P(value);
739#else
740 if (Z_TYPE_P(value) != IS_DOUBLE) convert_to_double(value);
741 l_data = (int64_t)Z_DVAL_P(value);
742#endif
743 transport.writeI64(l_data);
744 } return;
745 case T_DOUBLE: {
746 union {
747 int64_t c;
748 double d;
749 } a;
750 if (Z_TYPE_P(value) != IS_DOUBLE) convert_to_double(value);
751 a.d = Z_DVAL_P(value);

Callers 2

binary_serialize_specFunction · 0.85

Calls 11

throw_tprotocolexceptionFunction · 0.85
binary_serialize_specFunction · 0.85
zval_is_boolFunction · 0.85
convert_to_stringFunction · 0.85
ttype_is_scalarFunction · 0.85
writeI16Method · 0.65
writeI32Method · 0.65
writeI64Method · 0.65
writeStringMethod · 0.65
writeI8Method · 0.45

Tested by

no test coverage detected