本文整理汇总了C++中PHPInputTransport::readBytes方法的典型用法代码示例。如果您正苦于以下问题:C++ PHPInputTransport::readBytes方法的具体用法?C++ PHPInputTransport::readBytes怎么用?C++ PHPInputTransport::readBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHPInputTransport
的用法示例。
在下文中一共展示了PHPInputTransport::readBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: binary_deserialize
Variant binary_deserialize(int8_t thrift_typeID, PHPInputTransport& transport,
const Array& fieldspec) {
Variant ret;
switch (thrift_typeID) {
case T_STOP:
case T_VOID:
return init_null();
case T_STRUCT: {
Variant val;
if ((val = fieldspec.rvalAt(PHPTransport::s_class)).isNull()) {
throw_tprotocolexception("no class type in spec", INVALID_DATA);
skip_element(T_STRUCT, transport);
return init_null();
}
String structType = val.toString();
ret = createObject(structType);
if (ret.isNull()) {
// unable to create class entry
skip_element(T_STRUCT, transport);
return init_null();
}
Variant spec = HHVM_FN(hphp_get_static_property)(structType, s_TSPEC,
false);
if (!spec.is(KindOfArray)) {
char errbuf[128];
snprintf(errbuf, 128, "spec for %s is wrong type: %d\n",
structType.data(), ret.getType());
throw_tprotocolexception(String(errbuf, CopyString), INVALID_DATA);
return init_null();
}
binary_deserialize_spec(ret.toObject(), transport, spec.toArray());
return ret;
} break;
case T_BOOL: {
uint8_t c;
transport.readBytes(&c, 1);
return c != 0;
}
//case T_I08: // same numeric value as T_BYTE
case T_BYTE: {
uint8_t c;
transport.readBytes(&c, 1);
return Variant((int8_t)c);
}
case T_I16: {
uint16_t c;
transport.readBytes(&c, 2);
return Variant((int16_t)ntohs(c));
}
case T_I32: {
uint32_t c;
transport.readBytes(&c, 4);
return Variant((int32_t)ntohl(c));
}
case T_U64:
case T_I64: {
uint64_t c;
transport.readBytes(&c, 8);
return Variant((int64_t)ntohll(c));
}
case T_DOUBLE: {
union {
uint64_t c;
double d;
} a;
transport.readBytes(&(a.c), 8);
a.c = ntohll(a.c);
return a.d;
}
case T_FLOAT: {
union {
uint32_t c;
float d;
} a;
transport.readBytes(&(a.c), 4);
a.c = ntohl(a.c);
return a.d;
}
//case T_UTF7: // aliases T_STRING
case T_UTF8:
case T_UTF16:
case T_STRING: {
uint32_t size = transport.readU32();
if (size && (size + 1)) {
String s = String(size, ReserveString);
char* strbuf = s.mutableData();
transport.readBytes(strbuf, size);
s.setSize(size);
return s;
} else {
return empty_string_variant();
}
}
case T_MAP: { // array of key -> value
uint8_t types[2];
transport.readBytes(types, 2);
uint32_t size = transport.readU32();
Array keyspec = fieldspec.rvalAt(PHPTransport::s_key,
AccessFlags::Error_Key).toArray();
//.........这里部分代码省略.........
示例2: binary_deserialize
static
void binary_deserialize(int8_t thrift_typeID, PHPInputTransport& transport, zval* return_value, HashTable* fieldspec) {
ZVAL_NULL(return_value);
switch (thrift_typeID) {
case T_STOP:
case T_VOID:
RETURN_NULL();
return;
case T_STRUCT: {
zval* val_ptr = zend_hash_str_find(fieldspec, "class", sizeof("class")-1);
if (val_ptr == nullptr) {
throw_tprotocolexception("no class type in spec", INVALID_DATA);
skip_element(T_STRUCT, transport);
RETURN_NULL();
}
char* structType = Z_STRVAL_P(val_ptr);
// Create an object in PHP userland based on our spec
createObject(structType, return_value);
if (Z_TYPE_P(return_value) == IS_NULL) {
// unable to create class entry
skip_element(T_STRUCT, transport);
RETURN_NULL();
}
zval* spec = zend_read_static_property(Z_OBJCE_P(return_value), "_TSPEC", sizeof("_TSPEC")-1, false);
if (Z_TYPE_P(spec) != IS_ARRAY) {
char errbuf[128];
snprintf(errbuf, 128, "spec for %s is wrong type: %d\n", structType, Z_TYPE_P(spec));
throw_tprotocolexception(errbuf, INVALID_DATA);
RETURN_NULL();
}
binary_deserialize_spec(return_value, transport, Z_ARRVAL_P(spec));
return;
} break;
case T_BOOL: {
uint8_t c;
transport.readBytes(&c, 1);
RETURN_BOOL(c != 0);
}
//case T_I08: // same numeric value as T_BYTE
case T_BYTE: {
uint8_t c;
transport.readBytes(&c, 1);
RETURN_LONG((int8_t)c);
}
case T_I16: {
uint16_t c;
transport.readBytes(&c, 2);
RETURN_LONG((int16_t)ntohs(c));
}
case T_I32: {
uint32_t c;
transport.readBytes(&c, 4);
RETURN_LONG((int32_t)ntohl(c));
}
case T_U64:
case T_I64: {
uint64_t c;
transport.readBytes(&c, 8);
RETURN_LONG((int64_t)ntohll(c));
}
case T_DOUBLE: {
union {
uint64_t c;
double d;
} a;
transport.readBytes(&(a.c), 8);
a.c = ntohll(a.c);
RETURN_DOUBLE(a.d);
}
//case T_UTF7: // aliases T_STRING
case T_UTF8:
case T_UTF16:
case T_STRING: {
uint32_t size = transport.readU32();
if (size) {
char strbuf[size+1];
transport.readBytes(strbuf, size);
strbuf[size] = '\0';
ZVAL_STRINGL(return_value, strbuf, size);
} else {
ZVAL_EMPTY_STRING(return_value);
}
return;
}
case T_MAP: { // array of key -> value
uint8_t types[2];
transport.readBytes(types, 2);
uint32_t size = transport.readU32();
array_init(return_value);
zval *val_ptr;
val_ptr = zend_hash_str_find(fieldspec, "key", sizeof("key")-1);
HashTable* keyspec = Z_ARRVAL_P(val_ptr);
val_ptr = zend_hash_str_find(fieldspec, "val", sizeof("val")-1);
HashTable* valspec = Z_ARRVAL_P(val_ptr);
for (uint32_t s = 0; s < size; ++s) {
//.........这里部分代码省略.........
示例3: binary_deserialize
void binary_deserialize(int8_t thrift_typeID, PHPInputTransport& transport, zval* return_value, HashTable* fieldspec) {
zval** val_ptr;
Z_TYPE_P(return_value) = IS_NULL; // just in case
switch (thrift_typeID) {
case T_STOP:
case T_VOID:
RETURN_NULL();
return;
case T_STRUCT: {
if (zend_hash_find(fieldspec, "class", 6, (void**)&val_ptr) != SUCCESS) {
throw_tprotocolexception("no class type in spec", INVALID_DATA);
skip_element(T_STRUCT, transport);
RETURN_NULL();
}
char* structType = Z_STRVAL_PP(val_ptr);
createObject(structType, return_value);
if (Z_TYPE_P(return_value) == IS_NULL) {
// unable to create class entry
skip_element(T_STRUCT, transport);
RETURN_NULL();
}
TSRMLS_FETCH();
zval* spec = zend_read_static_property(zend_get_class_entry(return_value TSRMLS_CC), "_TSPEC", 6, false TSRMLS_CC);
if (Z_TYPE_P(spec) != IS_ARRAY) {
char errbuf[128];
snprintf(errbuf, 128, "spec for %s is wrong type: %d\n", structType, Z_TYPE_P(spec));
throw_tprotocolexception(errbuf, INVALID_DATA);
RETURN_NULL();
}
binary_deserialize_spec(return_value, transport, Z_ARRVAL_P(spec));
return;
}
break;
case T_BOOL: {
uint8_t c;
transport.readBytes(&c, 1);
RETURN_BOOL(c != 0);
}
//case T_I08: // same numeric value as T_BYTE
case T_BYTE: {
uint8_t c;
transport.readBytes(&c, 1);
RETURN_LONG(c);
}
case T_I16: {
uint16_t c;
transport.readBytes(&c, 2);
RETURN_LONG(ntohs(c));
}
case T_I32: {
uint32_t c;
transport.readBytes(&c, 4);
RETURN_LONG(ntohl(c));
}
case T_U64:
case T_I64: {
uint64_t c;
transport.readBytes(&c, 8);
RETURN_LONG(ntohll(c));
}
case T_DOUBLE: {
union {
uint64_t c;
double d;
} a;
transport.readBytes(&(a.c), 8);
a.c = ntohll(a.c);
RETURN_DOUBLE(a.d);
}
//case T_UTF7: // aliases T_STRING
case T_UTF8:
case T_UTF16:
case T_STRING: {
uint32_t size = transport.readU32();
if (size) {
char* strbuf = (char*) emalloc(size + 1);
transport.readBytes(strbuf, size);
strbuf[size] = '\0';
ZVAL_STRINGL(return_value, strbuf, size, 0);
} else {
ZVAL_EMPTY_STRING(return_value);
}
return;
}
case T_MAP: { // array of key -> value
uint8_t types[2];
transport.readBytes(types, 2);
uint32_t size = transport.readU32();
array_init(return_value);
zend_hash_find(fieldspec, "key", 4, (void**)&val_ptr);
HashTable* keyspec = Z_ARRVAL_PP(val_ptr);
zend_hash_find(fieldspec, "val", 4, (void**)&val_ptr);
HashTable* valspec = Z_ARRVAL_PP(val_ptr);
for (uint32_t s = 0; s < size; ++s) {
zval *value;
MAKE_STD_ZVAL(value);
//.........这里部分代码省略.........
示例4: binary_deserialize
Variant binary_deserialize(int8_t thrift_typeID, PHPInputTransport& transport,
CArrRef fieldspec) {
Variant ret;
switch (thrift_typeID) {
case T_STOP:
case T_VOID:
return uninit_null();
case T_STRUCT: {
Variant val;
if ((val = fieldspec.rvalAt(PHPTransport::s_class)).isNull()) {
throw_tprotocolexception("no class type in spec", INVALID_DATA);
skip_element(T_STRUCT, transport);
return uninit_null();
}
String structType = val.toString();
ret = createObject(structType);
if (ret.isNull()) {
// unable to create class entry
skip_element(T_STRUCT, transport);
return uninit_null();
}
Variant spec = f_hphp_get_static_property(structType, s_TSPEC, false);
if (!spec.is(KindOfArray)) {
char errbuf[128];
snprintf(errbuf, 128, "spec for %s is wrong type: %d\n",
structType.data(), ret.getType());
throw_tprotocolexception(String(errbuf, CopyString), INVALID_DATA);
return uninit_null();
}
binary_deserialize_spec(ret.toObject(), transport, spec.toArray());
return ret;
} break;
case T_BOOL: {
uint8_t c;
transport.readBytes(&c, 1);
return c != 0;
}
//case T_I08: // same numeric value as T_BYTE
case T_BYTE: {
uint8_t c;
transport.readBytes(&c, 1);
return Variant((int8_t)c);
}
case T_I16: {
uint16_t c;
transport.readBytes(&c, 2);
return Variant((int16_t)ntohs(c));
}
case T_I32: {
uint32_t c;
transport.readBytes(&c, 4);
return Variant((int32_t)ntohl(c));
}
case T_U64:
case T_I64: {
uint64_t c;
transport.readBytes(&c, 8);
return Variant((int64_t)ntohll(c));
}
case T_DOUBLE: {
union {
uint64_t c;
double d;
} a;
transport.readBytes(&(a.c), 8);
a.c = ntohll(a.c);
return a.d;
}
case T_FLOAT: {
union {
uint32_t c;
float d;
} a;
transport.readBytes(&(a.c), 4);
a.c = ntohl(a.c);
return a.d;
}
//case T_UTF7: // aliases T_STRING
case T_UTF8:
case T_UTF16:
case T_STRING: {
uint32_t size = transport.readU32();
if (size && (size + 1)) {
String s = String(size, ReserveString);
char* strbuf = s.bufferSlice().ptr;
transport.readBytes(strbuf, size);
return s.setSize(size);
} else {
return "";
}
}
case T_MAP: { // array of key -> value
uint8_t types[2];
transport.readBytes(types, 2);
uint32_t size = transport.readU32();
Array keyspec = fieldspec.rvalAt(PHPTransport::s_key,
AccessFlags::Error_Key).toArray();
Array valspec = fieldspec.rvalAt(PHPTransport::s_val,
AccessFlags::Error_Key).toArray();
//.........这里部分代码省略.........