Commit e82ba0b8 authored by Yilun Chong's avatar Yilun Chong Committed by GitHub

Merge branch 'master' into ConformanceTestYilunChong

parents 726ba33d ecca6ea9
......@@ -597,60 +597,63 @@ php_EXTRA_DIST= \
php/ext/google/protobuf/upb.c \
php/ext/google/protobuf/protobuf.c \
php/src/phpdoc.dist.xml \
php/src/Google/Protobuf/Internal/Descriptor.php \
php/src/Google/Protobuf/Internal/CodedInputStream.php \
php/src/Google/Protobuf/Internal/CodedOutputStream.php \
php/src/Google/Protobuf/Internal/DescriptorPool.php \
php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php \
php/src/Google/Protobuf/Internal/OneofField.php \
php/src/Google/Protobuf/Internal/MessageOptions.php \
php/src/Google/Protobuf/Internal/FileDescriptor.php \
php/src/Google/Protobuf/Internal/FileDescriptorProto.php \
php/src/Google/Protobuf/Internal/MapEntry.php \
php/src/Google/Protobuf/Internal/FieldDescriptor.php \
php/src/Google/Protobuf/Internal/FieldDescriptorProto.php \
php/src/Google/Protobuf/Internal/InputStream.php \
php/src/Google/Protobuf/Internal/UninterpretedOption.php \
php/src/Google/Protobuf/Internal/ServiceOptions.php \
php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php \
php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php \
php/src/Google/Protobuf/Internal/OneofDescriptor.php \
php/src/Google/Protobuf/Internal/OneofDescriptorProto.php \
php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php \
php/src/Google/Protobuf/Internal/OutputStream.php \
php/src/Google/Protobuf/Internal/MessageBuilderContext.php \
php/src/Google/Protobuf/Internal/EnumValueDescriptor.php \
php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php \
php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php \
php/src/Google/Protobuf/Internal/DescriptorProto.php \
php/src/Google/Protobuf/Internal/MapField.php \
php/src/Google/Protobuf/Internal/MapFieldIter.php \
php/src/Google/Protobuf/Internal/MethodDescriptorProto.php \
php/src/Google/Protobuf/Internal/DescriptorProto_ExtensionRange.php \
php/src/Google/Protobuf/Internal/DescriptorProto_ReservedRange.php \
php/src/Google/Protobuf/Internal/RepeatedField.php \
php/src/Google/Protobuf/Internal/RepeatedFieldIter.php \
php/src/Google/Protobuf/Internal/EnumValueOptions.php \
php/src/Google/Protobuf/Internal/MethodOptions.php \
php/src/Google/Protobuf/Internal/OneofOptions.php \
php/src/Google/Protobuf/Internal/Message.php \
php/src/Google/Protobuf/Internal/FileOptions.php \
php/src/Google/Protobuf/Internal/FileDescriptorSet.php \
php/src/Google/Protobuf/Internal/DescriptorProto.php \
php/src/Google/Protobuf/Internal/Descriptor.php \
php/src/Google/Protobuf/Internal/EnumBuilderContext.php \
php/src/Google/Protobuf/Internal/EnumDescriptor.php \
php/src/Google/Protobuf/Internal/EnumDescriptorProto.php \
php/src/Google/Protobuf/Internal/GPBWire.php \
php/src/Google/Protobuf/Internal/EnumOptions.php \
php/src/Google/Protobuf/Internal/EnumValueDescriptorProto.php \
php/src/Google/Protobuf/Internal/EnumValueDescriptor.php \
php/src/Google/Protobuf/Internal/EnumValueOptions.php \
php/src/Google/Protobuf/Internal/FieldDescriptorProto_Label.php \
php/src/Google/Protobuf/Internal/FieldDescriptorProto.php \
php/src/Google/Protobuf/Internal/FieldDescriptor.php \
php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php \
php/src/Google/Protobuf/Internal/FieldOptions_CType.php \
php/src/Google/Protobuf/Internal/FieldOptions_JSType.php \
php/src/Google/Protobuf/Internal/FieldOptions.php \
php/src/Google/Protobuf/Internal/FileDescriptorProto.php \
php/src/Google/Protobuf/Internal/FileDescriptorSet.php \
php/src/Google/Protobuf/Internal/FileDescriptor.php \
php/src/Google/Protobuf/Internal/FileOptions_OptimizeMode.php \
php/src/Google/Protobuf/Internal/FileOptions.php \
php/src/Google/Protobuf/Internal/GeneratedCodeInfo_Annotation.php \
php/src/Google/Protobuf/Internal/FieldDescriptorProto_Type.php \
php/src/Google/Protobuf/Internal/GeneratedCodeInfo.php \
php/src/Google/Protobuf/Internal/GPBDecodeException.php \
php/src/Google/Protobuf/Internal/GPBJsonWire.php \
php/src/Google/Protobuf/Internal/GPBLabel.php \
php/src/Google/Protobuf/Internal/GPBType.php \
php/src/Google/Protobuf/Internal/FieldOptions_JSType.php \
php/src/Google/Protobuf/Internal/GPBUtil.php \
php/src/Google/Protobuf/Internal/GPBWireType.php \
php/src/Google/Protobuf/Internal/GPBWire.php \
php/src/Google/Protobuf/Internal/MapEntry.php \
php/src/Google/Protobuf/Internal/MapFieldIter.php \
php/src/Google/Protobuf/Internal/MapField.php \
php/src/Google/Protobuf/Internal/MessageBuilderContext.php \
php/src/Google/Protobuf/Internal/MessageOptions.php \
php/src/Google/Protobuf/Internal/Message.php \
php/src/Google/Protobuf/Internal/MethodDescriptorProto.php \
php/src/Google/Protobuf/Internal/MethodOptions_IdempotencyLevel.php \
php/src/Google/Protobuf/Internal/MethodOptions.php \
php/src/Google/Protobuf/Internal/OneofDescriptorProto.php \
php/src/Google/Protobuf/Internal/OneofDescriptor.php \
php/src/Google/Protobuf/Internal/OneofField.php \
php/src/Google/Protobuf/Internal/OneofOptions.php \
php/src/Google/Protobuf/Internal/RawInputStream.php \
php/src/Google/Protobuf/Internal/RepeatedFieldIter.php \
php/src/Google/Protobuf/Internal/RepeatedField.php \
php/src/Google/Protobuf/Internal/ServiceDescriptorProto.php \
php/src/Google/Protobuf/Internal/ServiceOptions.php \
php/src/Google/Protobuf/Internal/SourceCodeInfo_Location.php \
php/src/Google/Protobuf/Internal/SourceCodeInfo.php \
php/src/Google/Protobuf/Internal/EnumOptions.php \
php/src/Google/Protobuf/Internal/GPBLabel.php \
php/src/Google/Protobuf/Internal/EnumBuilderContext.php \
php/src/Google/Protobuf/Internal/GPBUtil.php \
php/src/Google/Protobuf/Internal/FieldOptions_CType.php \
php/src/Google/Protobuf/Internal/GPBDecodeException.php \
php/src/Google/Protobuf/Internal/UninterpretedOption_NamePart.php \
php/src/Google/Protobuf/Internal/UninterpretedOption.php \
php/src/GPBMetadata/Google/Protobuf/Internal/Descriptor.php \
php/tests/array_test.php \
php/tests/autoload.php \
......@@ -658,6 +661,7 @@ php_EXTRA_DIST= \
php/tests/encode_decode_test.php \
php/tests/gdb_test.sh \
php/tests/generated_class_test.php \
php/tests/generated_phpdoc_test.php \
php/tests/map_field_test.php \
php/tests/memory_leak_test.php \
php/tests/php_implementation_test.php \
......@@ -672,10 +676,11 @@ php_EXTRA_DIST= \
php/tests/test_base.php \
php/tests/test_util.php \
php/tests/well_known_test.php \
php/tests/undefined_test.php \
php/README.md \
php/phpunit.xml \
php/composer.json \
php/generate_descriptor_protos.sh \
php/phpunit.xml \
composer.json
python_EXTRA_DIST= \
......@@ -963,9 +968,14 @@ EXTRA_DIST = $(@DIST_LANG@_EXTRA_DIST) \
examples/list_people.py \
examples/list_people_test.go \
protobuf.bzl \
python/release/wheel/build_wheel_manylinux.sh \
python/release/wheel/Dockerfile \
python/release/wheel/protobuf_optimized_pip.sh \
python/release/wheel/README.md \
six.BUILD \
util/python/BUILD
# Deletes all the files generated by autogen.sh.
MAINTAINERCLEANFILES = \
aclocal.m4 \
......
......@@ -315,7 +315,7 @@ conformance-csharp: $(other_language_protoc_outputs)
conformance-php:
@echo "Writing shortcut script conformance-php..."
@echo '#! /bin/sh' > conformance-php
@echo 'php ./conformance_php.php' >> conformance-php
@echo 'php -d auto_prepend_file=autoload.php ./conformance_php.php' >> conformance-php
@chmod +x conformance-php
conformance-php-c:
......@@ -346,6 +346,9 @@ test_php: protoc_middleman conformance-test-runner conformance-php $(other_langu
test_php_c: protoc_middleman conformance-test-runner conformance-php-c $(other_language_protoc_outputs)
./conformance-test-runner --enforce_recommended --failure_list failure_list_php_c.txt ./conformance-php-c
test_php_zts_c: protoc_middleman conformance-test-runner conformance-php-c $(other_language_protoc_outputs)
./conformance-test-runner --enforce_recommended --failure_list failure_list_php_zts_c.txt ./conformance-php-c
# These depend on library paths being properly set up. The easiest way to
# run them is to just use "tox" from the python dir.
test_python: protoc_middleman conformance-test-runner
......
<?php
define("GOOGLE_INTERNAL_NAMESPACE", "Google\\Protobuf\\Internal\\");
define("GOOGLE_NAMESPACE", "Google\\Protobuf\\");
define("GOOGLE_GPBMETADATA_NAMESPACE", "GPBMetadata\\Google\\Protobuf\\Internal\\");
function protobuf_autoloader_impl($class, $prefix) {
$length = strlen($prefix);
if ((substr($class, 0, $length) === $prefix)) {
$path = '../php/src/' . implode('/', array_map('ucwords', explode('\\', $class))) . '.php';
include_once $path;
}
}
function protobuf_autoloader($class) {
protobuf_autoloader_impl($class, GOOGLE_INTERNAL_NAMESPACE);
protobuf_autoloader_impl($class, GOOGLE_NAMESPACE);
protobuf_autoloader_impl($class, GOOGLE_GPBMETADATA_NAMESPACE);
}
spl_autoload_register('protobuf_autoloader');
......@@ -60,7 +60,7 @@ function doTest($request)
}
} elseif ($request->getPayload() == "json_payload") {
try {
$test_message->jsonDecode($request->getJsonPayload());
$test_message->mergeFromJsonString($request->getJsonPayload());
} catch (Exception $e) {
$response->setParseError($e->getMessage());
return $response;
......@@ -74,7 +74,7 @@ function doTest($request)
} elseif ($request->getRequestedOutputFormat() == WireFormat::PROTOBUF) {
$response->setProtobufPayload($test_message->serializeToString());
} elseif ($request->getRequestedOutputFormat() == WireFormat::JSON) {
$response->setJsonPayload($test_message->jsonEncode());
$response->setJsonPayload($test_message->serializeToJsonString());
}
return $response;
......@@ -86,7 +86,8 @@ function doTestIO()
if (strlen($length_bytes) == 0) {
return false; # EOF
} elseif (strlen($length_bytes) != 4) {
trigger_error("I/O error", E_USER_ERROR);
fwrite(STDERR, "I/O error\n");
return false;
}
$length = unpack("V", $length_bytes)[1];
......
This diff is collapsed.
......@@ -164,18 +164,21 @@ typedef struct {
int property_ofs; // properties table cache
uint32_t oneof_case_num; // oneof-case number to place in oneof_case field
const upb_msgdef *md; // msgdef, for oneof submessage handler
const upb_msgdef *parent_md; // msgdef, for parent submessage
} oneof_handlerdata_t;
static const void *newoneofhandlerdata(upb_handlers *h,
uint32_t ofs,
uint32_t case_ofs,
int property_ofs,
const upb_msgdef *m,
const upb_fielddef *f) {
oneof_handlerdata_t* hd =
(oneof_handlerdata_t*)malloc(sizeof(oneof_handlerdata_t));
hd->ofs = ofs;
hd->case_ofs = case_ofs;
hd->property_ofs = property_ofs;
hd->parent_md = m;
// We reuse the field tag number as a oneof union discriminant tag. Note that
// we don't expose these numbers to the user, so the only requirement is that
// we have some unique ID for each union case/possibility. The field tag
......@@ -284,10 +287,19 @@ DEFINE_SINGULAR_HANDLER(double, double)
#if PHP_MAJOR_VERSION < 7
static void *empty_php_string(zval** value_ptr) {
SEPARATE_ZVAL_IF_NOT_REF(value_ptr);
if (Z_TYPE_PP(value_ptr) == IS_STRING &&
!IS_INTERNED(Z_STRVAL_PP(value_ptr))) {
FREE(Z_STRVAL_PP(value_ptr));
}
ZVAL_EMPTY_STRING(*value_ptr);
return (void*)(*value_ptr);
}
#else
static void *empty_php_string(zval* value_ptr) {
if (Z_TYPE_P(value_ptr) == IS_STRING) {
zend_string_release(Z_STR_P(value_ptr));
}
ZVAL_EMPTY_STRING(value_ptr);
return value_ptr;
}
#endif
......@@ -462,7 +474,7 @@ static void map_slot_init(void* memory, upb_fieldtype_t type, zval* cache) {
*(zval***)memory = holder;
#else
*(zval**)memory = cache;
PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1);
// PHP_PROTO_ZVAL_STRINGL(*(zval**)memory, "", 0, 1);
#endif
break;
}
......@@ -654,6 +666,44 @@ DEFINE_ONEOF_HANDLER(double, double)
#undef DEFINE_ONEOF_HANDLER
static void oneof_cleanup(MessageHeader* msg,
const oneof_handlerdata_t* oneofdata) {
uint32_t old_case_num =
DEREF(message_data(msg), oneofdata->case_ofs, uint32_t);
if (old_case_num == 0) {
return;
}
const upb_fielddef* old_field =
upb_msgdef_itof(oneofdata->parent_md, old_case_num);
bool need_clean = false;
switch (upb_fielddef_type(old_field)) {
case UPB_TYPE_STRING:
case UPB_TYPE_BYTES:
need_clean = true;
break;
case UPB_TYPE_MESSAGE:
if (oneofdata->oneof_case_num != old_case_num) {
need_clean = true;
}
break;
default:
break;
}
if (need_clean) {
#if PHP_MAJOR_VERSION < 7
SEPARATE_ZVAL_IF_NOT_REF(
DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*));
php_proto_zval_ptr_dtor(
*DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*));
MAKE_STD_ZVAL(*DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*));
ZVAL_NULL(*DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*));
#endif
}
}
// Handlers for string/bytes in a oneof.
static void *oneofbytes_handler(void *closure,
const void *hd,
......@@ -661,6 +711,8 @@ static void *oneofbytes_handler(void *closure,
MessageHeader* msg = closure;
const oneof_handlerdata_t *oneofdata = hd;
oneof_cleanup(msg, oneofdata);
DEREF(message_data(msg), oneofdata->case_ofs, uint32_t) =
oneofdata->oneof_case_num;
DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) =
......@@ -691,22 +743,11 @@ static void* oneofsubmsg_handler(void* closure, const void* hd) {
MessageHeader* submsg;
if (oldcase != oneofdata->oneof_case_num) {
// Ideally, we should clean up the old data. However, we don't even know the
// type of the old data. So, we will defer the desctruction of the old data
// to the time that containing message's destroyed or the same oneof field
// is accessed again and find that the old data hasn't been cleaned.
DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) =
&(msg->std.properties_table)[oneofdata->property_ofs];
// Old data was't cleaned when the oneof was accessed from another field.
if (Z_TYPE_P(CACHED_PTR_TO_ZVAL_PTR(DEREF(
message_data(msg), oneofdata->ofs, CACHED_VALUE*))) != IS_NULL) {
php_proto_zval_ptr_dtor(
CACHED_PTR_TO_ZVAL_PTR(
DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*)));
}
oneof_cleanup(msg, oneofdata);
// Create new message.
DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*) =
&(msg->std.properties_table)[oneofdata->property_ofs];
ZVAL_OBJ(CACHED_PTR_TO_ZVAL_PTR(
DEREF(message_data(msg), oneofdata->ofs, CACHED_VALUE*)),
subklass->create_object(subklass TSRMLS_CC));
......@@ -856,6 +897,7 @@ static void add_handlers_for_mapentry(const upb_msgdef* msgdef, upb_handlers* h,
// Set up handlers for a oneof field.
static void add_handlers_for_oneof_field(upb_handlers *h,
const upb_msgdef *m,
const upb_fielddef *f,
size_t offset,
size_t oneof_case_offset,
......@@ -864,7 +906,7 @@ static void add_handlers_for_oneof_field(upb_handlers *h,
upb_handlerattr attr = UPB_HANDLERATTR_INITIALIZER;
upb_handlerattr_sethandlerdata(
&attr, newoneofhandlerdata(h, offset, oneof_case_offset,
property_cache_offset, f));
property_cache_offset, m, f));
switch (upb_fielddef_type(f)) {
......@@ -936,8 +978,8 @@ static void add_handlers_for_message(const void* closure,
desc->layout->fields[upb_fielddef_index(f)].case_offset;
int property_cache_index =
desc->layout->fields[upb_fielddef_index(f)].cache_index;
add_handlers_for_oneof_field(h, f, offset, oneof_case_offset,
property_cache_index);
add_handlers_for_oneof_field(h, desc->msgdef, f, offset,
oneof_case_offset, property_cache_index);
} else if (is_map_field(f)) {
add_handlers_for_mapfield(h, f, offset, desc);
} else if (upb_fielddef_isseq(f)) {
......@@ -1198,7 +1240,7 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
} else if (upb_fielddef_isstring(f)) {
zval* str = CACHED_PTR_TO_ZVAL_PTR(
DEREF(message_data(msg), offset, CACHED_VALUE*));
if (Z_STRLEN_P(str) > 0) {
if (containing_oneof || Z_STRLEN_P(str) > 0) {
putstr(str, f, sink);
}
} else if (upb_fielddef_issubmsg(f)) {
......@@ -1221,10 +1263,10 @@ static void putrawmsg(MessageHeader* msg, const Descriptor* desc,
T(UPB_TYPE_DOUBLE, double, double, 0.0)
T(UPB_TYPE_BOOL, bool, uint8_t, 0)
case UPB_TYPE_ENUM:
T(UPB_TYPE_INT32, int32, int32_t, 0)
T(UPB_TYPE_UINT32, uint32, uint32_t, 0)
T(UPB_TYPE_INT64, int64, int64_t, 0)
T(UPB_TYPE_UINT64, uint64, uint64_t, 0)
T(UPB_TYPE_INT32, int32, int32_t, 0)
T(UPB_TYPE_UINT32, uint32, uint32_t, 0)
T(UPB_TYPE_INT64, int64, int64_t, 0)
T(UPB_TYPE_UINT64, uint64, uint64_t, 0)
case UPB_TYPE_STRING:
case UPB_TYPE_BYTES:
......@@ -1246,18 +1288,23 @@ static void putstr(zval* str, const upb_fielddef *f, upb_sink *sink) {
assert(Z_TYPE_P(str) == IS_STRING);
// Ensure that the string has the correct encoding. We also check at field-set
// time, but the user may have mutated the string object since then.
if (upb_fielddef_type(f) == UPB_TYPE_STRING &&
!is_structurally_valid_utf8(Z_STRVAL_P(str), Z_STRLEN_P(str))) {
zend_error(E_USER_ERROR, "Given string is not UTF8 encoded.");
return;
}
upb_sink_startstr(sink, getsel(f, UPB_HANDLER_STARTSTR), Z_STRLEN_P(str),
&subsink);
upb_sink_putstring(&subsink, getsel(f, UPB_HANDLER_STRING), Z_STRVAL_P(str),
Z_STRLEN_P(str), NULL);
// For oneof string field, we may get here with string length is zero.
if (Z_STRLEN_P(str) > 0) {
// Ensure that the string has the correct encoding. We also check at
// field-set time, but the user may have mutated the string object since
// then.
if (upb_fielddef_type(f) == UPB_TYPE_STRING &&
!is_structurally_valid_utf8(Z_STRVAL_P(str), Z_STRLEN_P(str))) {
zend_error(E_USER_ERROR, "Given string is not UTF8 encoded.");
return;
}
upb_sink_putstring(&subsink, getsel(f, UPB_HANDLER_STRING), Z_STRVAL_P(str),
Z_STRLEN_P(str), NULL);
}
upb_sink_endstr(sink, getsel(f, UPB_HANDLER_ENDSTR));
}
......@@ -1452,7 +1499,7 @@ PHP_METHOD(Message, mergeFromString) {
}
}
PHP_METHOD(Message, jsonEncode) {
PHP_METHOD(Message, serializeToJsonString) {
Descriptor* desc =
UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(getThis())));
......@@ -1483,13 +1530,14 @@ PHP_METHOD(Message, jsonEncode) {
}
}
PHP_METHOD(Message, jsonDecode) {
PHP_METHOD(Message, mergeFromJsonString) {
Descriptor* desc =
UNBOX_HASHTABLE_VALUE(Descriptor, get_ce_obj(Z_OBJCE_P(getThis())));
MessageHeader* msg = UNBOX(MessageHeader, getThis());
char *data = NULL;
int data_len;
PHP_PROTO_SIZE data_len;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &data, &data_len) ==
FAILURE) {
return;
......
......@@ -40,8 +40,8 @@ static zend_function_entry message_methods[] = {
PHP_ME(Message, clear, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, serializeToString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, mergeFromString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, jsonEncode, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, jsonDecode, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, serializeToJsonString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, mergeFromJsonString, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, mergeFrom, NULL, ZEND_ACC_PUBLIC)
PHP_ME(Message, readOneof, NULL, ZEND_ACC_PROTECTED)
PHP_ME(Message, writeOneof, NULL, ZEND_ACC_PROTECTED)
......
......@@ -593,8 +593,8 @@ const upb_pbdecodermethod *new_fillmsg_decodermethod(Descriptor *desc,
PHP_METHOD(Message, serializeToString);
PHP_METHOD(Message, mergeFromString);
PHP_METHOD(Message, jsonEncode);
PHP_METHOD(Message, jsonDecode);
PHP_METHOD(Message, serializeToJsonString);
PHP_METHOD(Message, mergeFromJsonString);
// -----------------------------------------------------------------------------
// Type check / conversion.
......
......@@ -2308,6 +2308,9 @@ bool upb_symtab_addfile(upb_symtab *s, upb_filedef *file, upb_status *status) {
bool ret;
n = upb_filedef_defcount(file);
if (n == 0) {
return true;
}
defs = upb_gmalloc(sizeof(*defs) * n);
if (defs == NULL) {
......
......@@ -7,6 +7,7 @@
<file>tests/array_test.php</file>
<file>tests/encode_decode_test.php</file>
<file>tests/generated_class_test.php</file>
<file>tests/generated_phpdoc_test.php</file>
<file>tests/map_field_test.php</file>
<file>tests/well_known_test.php</file>
</testsuite>
......
......@@ -34,7 +34,7 @@ namespace Google\Protobuf\Internal;
use Google\Protobuf\Internal\Uint64;
class InputStream
class CodedInputStream
{
private $buffer;
......@@ -73,7 +73,7 @@ class InputStream
$this->current += $amount;
}
private function bufferSize()
public function bufferSize()
{
return $this->buffer_end - $this->current;
}
......@@ -172,6 +172,9 @@ class InputStream
} while ($b & 0x80);
$var = GPBUtil::combineInt32ToInt64($high, $low);
if (bccomp($var, 0) < 0) {
$var = bcadd($var, "18446744073709551616");
}
} else {
$result = 0;
$shift = 0;
......
......@@ -32,7 +32,7 @@
namespace Google\Protobuf\Internal;
class OutputStream
class CodedOutputStream
{
private $buffer;
......@@ -53,10 +53,10 @@ class OutputStream
return $this->buffer;
}
public function writeVarint32($value)
public function writeVarint32($value, $trim)
{
$bytes = str_repeat(chr(0), self::MAX_VARINT64_BYTES);
$size = self::writeVarintToArray($value, $bytes);
$size = self::writeVarintToArray($value, $bytes, $trim);
return $this->writeRaw($bytes, $size);
}
......@@ -83,7 +83,7 @@ class OutputStream
public function writeTag($tag)
{
return $this->writeVarint32($tag);
return $this->writeVarint32($tag, true);
}
public function writeRaw($data, $size)
......@@ -101,19 +101,19 @@ class OutputStream
return true;
}
private static function writeVarintToArray($value, &$buffer)
private static function writeVarintToArray($value, &$buffer, $trim = false)
{
$current = 0;
$high = 0;
$low = 0;
if (PHP_INT_SIZE == 4) {
GPBUtil::divideInt64ToInt32($value, $high, $low);
GPBUtil::divideInt64ToInt32($value, $high, $low, $trim);
} else {
$low = $value;
}
while ($low >= 0x80 || $low < 0) {
while (($low >= 0x80 || $low < 0) || $high != 0) {
$buffer[$current] = chr($low | 0x80);
$value = ($value >> 7) & ~(0x7F << ((PHP_INT_SIZE << 3) - 7));
$carry = ($high & 0x7F) << ((PHP_INT_SIZE << 3) - 7);
......
......@@ -37,6 +37,8 @@ class Descriptor
private $full_name;
private $field = [];
private $json_to_field = [];
private $name_to_field = [];
private $nested_type = [];
private $enum_type = [];
private $klass;
......@@ -66,6 +68,8 @@ class Descriptor
public function addField($field)
{
$this->field[$field->getNumber()] = $field;
$this->json_to_field[$field->getJsonName()] = $field;
$this->name_to_field[$field->getName()] = $field;
}
public function getField()
......@@ -95,11 +99,29 @@ class Descriptor
public function getFieldByNumber($number)
{
if (!isset($this->field[$number])) {
return NULL;
} else {
return $this->field[$number];
}
if (!isset($this->field[$number])) {
return NULL;
} else {
return $this->field[$number];
}
}
public function getFieldByJsonName($json_name)
{
if (!isset($this->json_to_field[$json_name])) {
return NULL;
} else {
return $this->json_to_field[$json_name];
}
}
public function getFieldByName($name)
{
if (!isset($this->name_to_field[$name])) {
return NULL;
} else {
return $this->name_to_field[$name];
}
}
public function setClass($klass)
......
......@@ -12,17 +12,17 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Protobuf type <code>google.protobuf.DescriptorProto.ExtensionRange</code>
* Generated from protobuf message <code>google.protobuf.DescriptorProto.ExtensionRange</code>
*/
class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message
{
/**
* <code>optional int32 start = 1;</code>
* Generated from protobuf field <code>optional int32 start = 1;</code>
*/
private $start = 0;
private $has_start = false;
/**
* <code>optional int32 end = 2;</code>
* Generated from protobuf field <code>optional int32 end = 2;</code>
*/
private $end = 0;
private $has_end = false;
......@@ -33,7 +33,8 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional int32 start = 1;</code>
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @return int
*/
public function getStart()
{
......@@ -41,7 +42,9 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional int32 start = 1;</code>
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @param int $var
* @return $this
*/
public function setStart($var)
{
......@@ -58,7 +61,8 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional int32 end = 2;</code>
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @return int
*/
public function getEnd()
{
......@@ -66,7 +70,9 @@ class DescriptorProto_ExtensionRange extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional int32 end = 2;</code>
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
......
......@@ -12,31 +12,25 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* <pre>
* Range of reserved tag numbers. Reserved tag numbers may not be used by
* fields or extension ranges in the same message. Reserved ranges may
* not overlap.
* </pre>
*
* Protobuf type <code>google.protobuf.DescriptorProto.ReservedRange</code>
* Generated from protobuf message <code>google.protobuf.DescriptorProto.ReservedRange</code>
*/
class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message
{
/**
* <pre>
* Inclusive.
* </pre>
*
* <code>optional int32 start = 1;</code>
* Generated from protobuf field <code>optional int32 start = 1;</code>
*/
private $start = 0;
private $has_start = false;
/**
* <pre>
* Exclusive.
* </pre>
*
* <code>optional int32 end = 2;</code>
* Generated from protobuf field <code>optional int32 end = 2;</code>
*/
private $end = 0;
private $has_end = false;
......@@ -47,11 +41,10 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Inclusive.
* </pre>
*
* <code>optional int32 start = 1;</code>
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @return int
*/
public function getStart()
{
......@@ -59,11 +52,11 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Inclusive.
* </pre>
*
* <code>optional int32 start = 1;</code>
* Generated from protobuf field <code>optional int32 start = 1;</code>
* @param int $var
* @return $this
*/
public function setStart($var)
{
......@@ -80,11 +73,10 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Exclusive.
* </pre>
*
* <code>optional int32 end = 2;</code>
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @return int
*/
public function getEnd()
{
......@@ -92,11 +84,11 @@ class DescriptorProto_ReservedRange extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Exclusive.
* </pre>
*
* <code>optional int32 end = 2;</code>
* Generated from protobuf field <code>optional int32 end = 2;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
......
......@@ -8,6 +8,7 @@ class EnumDescriptor
private $klass;
private $full_name;
private $value;
private $name_to_value;
public function setFullName($full_name)
{
......@@ -22,6 +23,17 @@ class EnumDescriptor
public function addValue($number, $value)
{
$this->value[$number] = $value;
$this->name_to_value[$value->getName()] = $value;
}
public function getValueByNumber($number)
{
return $this->value[$number];
}
public function getValueByName($name)
{
return $this->name_to_value[$name];
}
public function setClass($klass)
......@@ -50,6 +62,10 @@ class EnumDescriptor
$fullname);
$desc->setFullName($fullname);
$desc->setClass($classname);
$values = $proto->getValue();
foreach ($values as $value) {
$desc->addValue($value->getNumber(), $value);
}
return $desc;
}
......
......@@ -12,26 +12,24 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* <pre>
* Describes an enum type.
* </pre>
*
* Protobuf type <code>google.protobuf.EnumDescriptorProto</code>
* Generated from protobuf message <code>google.protobuf.EnumDescriptorProto</code>
*/
class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* <code>optional string name = 1;</code>
* Generated from protobuf field <code>optional string name = 1;</code>
*/
private $name = '';
private $has_name = false;
/**
* <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
* Generated from protobuf field <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
*/
private $value;
private $has_value = false;
/**
* <code>optional .google.protobuf.EnumOptions options = 3;</code>
* Generated from protobuf field <code>optional .google.protobuf.EnumOptions options = 3;</code>
*/
private $options = null;
private $has_options = false;
......@@ -42,7 +40,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional string name = 1;</code>
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
......@@ -50,7 +49,9 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional string name = 1;</code>
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
......@@ -67,7 +68,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
* Generated from protobuf field <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getValue()
{
......@@ -75,7 +77,9 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
* Generated from protobuf field <code>repeated .google.protobuf.EnumValueDescriptorProto value = 2;</code>
* @param \Google\Protobuf\Internal\EnumValueDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setValue(&$var)
{
......@@ -92,7 +96,8 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional .google.protobuf.EnumOptions options = 3;</code>
* Generated from protobuf field <code>optional .google.protobuf.EnumOptions options = 3;</code>
* @return \Google\Protobuf\Internal\EnumOptions
*/
public function getOptions()
{
......@@ -100,7 +105,9 @@ class EnumDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional .google.protobuf.EnumOptions options = 3;</code>
* Generated from protobuf field <code>optional .google.protobuf.EnumOptions options = 3;</code>
* @param \Google\Protobuf\Internal\EnumOptions $var
* @return $this
*/
public function setOptions(&$var)
{
......
......@@ -12,38 +12,32 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Protobuf type <code>google.protobuf.EnumOptions</code>
* Generated from protobuf message <code>google.protobuf.EnumOptions</code>
*/
class EnumOptions extends \Google\Protobuf\Internal\Message
{
/**
* <pre>
* Set this option to true to allow mapping different tag names to the same
* value.
* </pre>
*
* <code>optional bool allow_alias = 2;</code>
* Generated from protobuf field <code>optional bool allow_alias = 2;</code>
*/
private $allow_alias = false;
private $has_allow_alias = false;
/**
* <pre>
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
* </pre>
*
* <code>optional bool deprecated = 3 [default = false];</code>
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
*/
private $deprecated = false;
private $has_deprecated = false;
/**
* <pre>
* The parser stores options it doesn't recognize here. See above.
* </pre>
*
* <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
private $has_uninterpreted_option = false;
......@@ -54,12 +48,11 @@ class EnumOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Set this option to true to allow mapping different tag names to the same
* value.
* </pre>
*
* <code>optional bool allow_alias = 2;</code>
* Generated from protobuf field <code>optional bool allow_alias = 2;</code>
* @return bool
*/
public function getAllowAlias()
{
......@@ -67,12 +60,12 @@ class EnumOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Set this option to true to allow mapping different tag names to the same
* value.
* </pre>
*
* <code>optional bool allow_alias = 2;</code>
* Generated from protobuf field <code>optional bool allow_alias = 2;</code>
* @param bool $var
* @return $this
*/
public function setAllowAlias($var)
{
......@@ -89,14 +82,13 @@ class EnumOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
* </pre>
*
* <code>optional bool deprecated = 3 [default = false];</code>
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
......@@ -104,14 +96,14 @@ class EnumOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Is this enum deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum, or it will be completely ignored; in the very least, this
* is a formalization for deprecating enums.
* </pre>
*
* <code>optional bool deprecated = 3 [default = false];</code>
* Generated from protobuf field <code>optional bool deprecated = 3 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
......@@ -128,11 +120,10 @@ class EnumOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* The parser stores options it doesn't recognize here. See above.
* </pre>
*
* <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
......@@ -140,11 +131,11 @@ class EnumOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* The parser stores options it doesn't recognize here. See above.
* </pre>
*
* <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption(&$var)
{
......
......@@ -34,4 +34,26 @@ namespace Google\Protobuf\Internal;
class EnumValueDescriptor
{
private $name;
private $number;
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public function setNumber($number)
{
$this->number = $number;
}
public function getNumber()
{
return $this->number;
}
}
......@@ -12,26 +12,24 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* <pre>
* Describes a value within an enum.
* </pre>
*
* Protobuf type <code>google.protobuf.EnumValueDescriptorProto</code>
* Generated from protobuf message <code>google.protobuf.EnumValueDescriptorProto</code>
*/
class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* <code>optional string name = 1;</code>
* Generated from protobuf field <code>optional string name = 1;</code>
*/
private $name = '';
private $has_name = false;
/**
* <code>optional int32 number = 2;</code>
* Generated from protobuf field <code>optional int32 number = 2;</code>
*/
private $number = 0;
private $has_number = false;
/**
* <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
* Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
*/
private $options = null;
private $has_options = false;
......@@ -42,7 +40,8 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional string name = 1;</code>
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
......@@ -50,7 +49,9 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional string name = 1;</code>
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
......@@ -67,7 +68,8 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional int32 number = 2;</code>
* Generated from protobuf field <code>optional int32 number = 2;</code>
* @return int
*/
public function getNumber()
{
......@@ -75,7 +77,9 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional int32 number = 2;</code>
* Generated from protobuf field <code>optional int32 number = 2;</code>
* @param int $var
* @return $this
*/
public function setNumber($var)
{
......@@ -92,7 +96,8 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
* Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
* @return \Google\Protobuf\Internal\EnumValueOptions
*/
public function getOptions()
{
......@@ -100,7 +105,9 @@ class EnumValueDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
* Generated from protobuf field <code>optional .google.protobuf.EnumValueOptions options = 3;</code>
* @param \Google\Protobuf\Internal\EnumValueOptions $var
* @return $this
*/
public function setOptions(&$var)
{
......
......@@ -12,28 +12,24 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Protobuf type <code>google.protobuf.EnumValueOptions</code>
* Generated from protobuf message <code>google.protobuf.EnumValueOptions</code>
*/
class EnumValueOptions extends \Google\Protobuf\Internal\Message
{
/**
* <pre>
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
* </pre>
*
* <code>optional bool deprecated = 1 [default = false];</code>
* Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code>
*/
private $deprecated = false;
private $has_deprecated = false;
/**
* <pre>
* The parser stores options it doesn't recognize here. See above.
* </pre>
*
* <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
*/
private $uninterpreted_option;
private $has_uninterpreted_option = false;
......@@ -44,14 +40,13 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
* </pre>
*
* <code>optional bool deprecated = 1 [default = false];</code>
* Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code>
* @return bool
*/
public function getDeprecated()
{
......@@ -59,14 +54,14 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Is this enum value deprecated?
* Depending on the target platform, this can emit Deprecated annotations
* for the enum value, or it will be completely ignored; in the very least,
* this is a formalization for deprecating enum values.
* </pre>
*
* <code>optional bool deprecated = 1 [default = false];</code>
* Generated from protobuf field <code>optional bool deprecated = 1 [default = false];</code>
* @param bool $var
* @return $this
*/
public function setDeprecated($var)
{
......@@ -83,11 +78,10 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* The parser stores options it doesn't recognize here. See above.
* </pre>
*
* <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getUninterpretedOption()
{
......@@ -95,11 +89,11 @@ class EnumValueOptions extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* The parser stores options it doesn't recognize here. See above.
* </pre>
*
* <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* Generated from protobuf field <code>repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;</code>
* @param \Google\Protobuf\Internal\UninterpretedOption[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setUninterpretedOption(&$var)
{
......
......@@ -36,6 +36,7 @@ class FieldDescriptor
{
private $name;
private $json_name;
private $setter;
private $getter;
private $number;
......@@ -67,6 +68,16 @@ class FieldDescriptor
return $this->name;
}
public function setJsonName($json_name)
{
$this->json_name = $json_name;
}
public function getJsonName()
{
return $this->json_name;
}
public function setSetter($setter)
{
$this->setter = $setter;
......@@ -172,23 +183,49 @@ class FieldDescriptor
$field_type !== GPBType::BYTES);
}
public static function getFieldDescriptor(
$name,
$label,
$type,
$number,
$oneof_index,
$packed,
$type_name = null)
public static function getFieldDescriptor($proto)
{
$type_name = null;
$type = $proto->getType();
switch ($type) {
case GPBType::MESSAGE:
case GPBType::GROUP:
case GPBType::ENUM:
$type_name = $proto->getTypeName();
break;
default:
break;
}
$oneof_index = $proto->hasOneofIndex() ? $proto->getOneofIndex() : -1;
$packed = false;
$options = $proto->getOptions();
if ($options !== null) {
$packed = $options->getPacked();
}
$field = new FieldDescriptor();
$field->setName($name);
$camel_name = implode('', array_map('ucwords', explode('_', $name)));
$field->setName($proto->getName());
$json_name = $proto->hasJsonName() ? $proto->getJsonName() :
lcfirst(implode('', array_map('ucwords', explode('_', $proto->getName()))));
if ($proto->hasJsonName()) {
$json_name = $proto->getJsonName();
} else {
$proto_name = $proto->getName();
$json_name = implode('', array_map('ucwords', explode('_', $proto_name)));
if ($proto_name[0] !== "_" && !ctype_upper($proto_name[0])) {
$json_name = lcfirst($json_name);
}
}
$field->setJsonName($json_name);
$camel_name = implode('', array_map('ucwords', explode('_', $proto->getName())));
$field->setGetter('get' . $camel_name);
$field->setSetter('set' . $camel_name);
$field->setType($type);
$field->setNumber($number);
$field->setLabel($label);
$field->setType($proto->getType());
$field->setNumber($proto->getNumber());
$field->setLabel($proto->getLabel());
$field->setPacked($packed);
$field->setOneofIndex($oneof_index);
......@@ -211,26 +248,6 @@ class FieldDescriptor
public static function buildFromProto($proto)
{
$type_name = null;
switch ($proto->getType()) {
case GPBType::MESSAGE:
case GPBType::GROUP:
case GPBType::ENUM:
$type_name = $proto->getTypeName();
break;
default:
break;
}
$oneof_index = $proto->hasOneofIndex() ? $proto->getOneofIndex() : -1;
$packed = false;
$options = $proto->getOptions();
if ($options !== null) {
$packed = $options->getPacked();
}
return FieldDescriptor::getFieldDescriptor(
$proto->getName(), $proto->getLabel(), $proto->getType(),
$proto->getNumber(), $oneof_index, $packed, $type_name);
return FieldDescriptor::getFieldDescriptor($proto);
}
}
......@@ -5,24 +5,22 @@
namespace Google\Protobuf\Internal;
/**
* Protobuf enum <code>google.protobuf.FieldDescriptorProto.Label</code>
* Protobuf enum <code>Google\Protobuf\Internal</code>
*/
class FieldDescriptorProto_Label
{
/**
* <pre>
* 0 is reserved for errors
* </pre>
*
* <code>LABEL_OPTIONAL = 1;</code>
* Generated from protobuf enum <code>LABEL_OPTIONAL = 1;</code>
*/
const LABEL_OPTIONAL = 1;
/**
* <code>LABEL_REQUIRED = 2;</code>
* Generated from protobuf enum <code>LABEL_REQUIRED = 2;</code>
*/
const LABEL_REQUIRED = 2;
/**
* <code>LABEL_REPEATED = 3;</code>
* Generated from protobuf enum <code>LABEL_REPEATED = 3;</code>
*/
const LABEL_REPEATED = 3;
}
......
......@@ -5,118 +5,102 @@
namespace Google\Protobuf\Internal;
/**
* Protobuf enum <code>google.protobuf.FieldDescriptorProto.Type</code>
* Protobuf enum <code>Google\Protobuf\Internal</code>
*/
class FieldDescriptorProto_Type
{
/**
* <pre>
* 0 is reserved for errors.
* Order is weird for historical reasons.
* </pre>
*
* <code>TYPE_DOUBLE = 1;</code>
* Generated from protobuf enum <code>TYPE_DOUBLE = 1;</code>
*/
const TYPE_DOUBLE = 1;
/**
* <code>TYPE_FLOAT = 2;</code>
* Generated from protobuf enum <code>TYPE_FLOAT = 2;</code>
*/
const TYPE_FLOAT = 2;
/**
* <pre>
* Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
* negative values are likely.
* </pre>
*
* <code>TYPE_INT64 = 3;</code>
* Generated from protobuf enum <code>TYPE_INT64 = 3;</code>
*/
const TYPE_INT64 = 3;
/**
* <code>TYPE_UINT64 = 4;</code>
* Generated from protobuf enum <code>TYPE_UINT64 = 4;</code>
*/
const TYPE_UINT64 = 4;
/**
* <pre>
* Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
* negative values are likely.
* </pre>
*
* <code>TYPE_INT32 = 5;</code>
* Generated from protobuf enum <code>TYPE_INT32 = 5;</code>
*/
const TYPE_INT32 = 5;
/**
* <code>TYPE_FIXED64 = 6;</code>
* Generated from protobuf enum <code>TYPE_FIXED64 = 6;</code>
*/
const TYPE_FIXED64 = 6;
/**
* <code>TYPE_FIXED32 = 7;</code>
* Generated from protobuf enum <code>TYPE_FIXED32 = 7;</code>
*/
const TYPE_FIXED32 = 7;
/**
* <code>TYPE_BOOL = 8;</code>
* Generated from protobuf enum <code>TYPE_BOOL = 8;</code>
*/
const TYPE_BOOL = 8;
/**
* <code>TYPE_STRING = 9;</code>
* Generated from protobuf enum <code>TYPE_STRING = 9;</code>
*/
const TYPE_STRING = 9;
/**
* <pre>
* Tag-delimited aggregate.
* Group type is deprecated and not supported in proto3. However, Proto3
* implementations should still be able to parse the group wire format and
* treat group fields as unknown fields.
* </pre>
*
* <code>TYPE_GROUP = 10;</code>
* Generated from protobuf enum <code>TYPE_GROUP = 10;</code>
*/
const TYPE_GROUP = 10;
/**
* <pre>
* Length-delimited aggregate.
* </pre>
*
* <code>TYPE_MESSAGE = 11;</code>
* Generated from protobuf enum <code>TYPE_MESSAGE = 11;</code>
*/
const TYPE_MESSAGE = 11;
/**
* <pre>
* New in version 2.
* </pre>
*
* <code>TYPE_BYTES = 12;</code>
* Generated from protobuf enum <code>TYPE_BYTES = 12;</code>
*/
const TYPE_BYTES = 12;
/**
* <code>TYPE_UINT32 = 13;</code>
* Generated from protobuf enum <code>TYPE_UINT32 = 13;</code>
*/
const TYPE_UINT32 = 13;
/**
* <code>TYPE_ENUM = 14;</code>
* Generated from protobuf enum <code>TYPE_ENUM = 14;</code>
*/
const TYPE_ENUM = 14;
/**
* <code>TYPE_SFIXED32 = 15;</code>
* Generated from protobuf enum <code>TYPE_SFIXED32 = 15;</code>
*/
const TYPE_SFIXED32 = 15;
/**
* <code>TYPE_SFIXED64 = 16;</code>
* Generated from protobuf enum <code>TYPE_SFIXED64 = 16;</code>
*/
const TYPE_SFIXED64 = 16;
/**
* <pre>
* Uses ZigZag encoding.
* </pre>
*
* <code>TYPE_SINT32 = 17;</code>
* Generated from protobuf enum <code>TYPE_SINT32 = 17;</code>
*/
const TYPE_SINT32 = 17;
/**
* <pre>
* Uses ZigZag encoding.
* </pre>
*
* <code>TYPE_SINT64 = 18;</code>
* Generated from protobuf enum <code>TYPE_SINT64 = 18;</code>
*/
const TYPE_SINT64 = 18;
}
......
......@@ -5,24 +5,22 @@
namespace Google\Protobuf\Internal;
/**
* Protobuf enum <code>google.protobuf.FieldOptions.CType</code>
* Protobuf enum <code>Google\Protobuf\Internal</code>
*/
class FieldOptions_CType
{
/**
* <pre>
* Default mode.
* </pre>
*
* <code>STRING = 0;</code>
* Generated from protobuf enum <code>STRING = 0;</code>
*/
const STRING = 0;
/**
* <code>CORD = 1;</code>
* Generated from protobuf enum <code>CORD = 1;</code>
*/
const CORD = 1;
/**
* <code>STRING_PIECE = 2;</code>
* Generated from protobuf enum <code>STRING_PIECE = 2;</code>
*/
const STRING_PIECE = 2;
}
......
......@@ -5,32 +5,26 @@
namespace Google\Protobuf\Internal;
/**
* Protobuf enum <code>google.protobuf.FieldOptions.JSType</code>
* Protobuf enum <code>Google\Protobuf\Internal</code>
*/
class FieldOptions_JSType
{
/**
* <pre>
* Use the default type.
* </pre>
*
* <code>JS_NORMAL = 0;</code>
* Generated from protobuf enum <code>JS_NORMAL = 0;</code>
*/
const JS_NORMAL = 0;
/**
* <pre>
* Use JavaScript strings.
* </pre>
*
* <code>JS_STRING = 1;</code>
* Generated from protobuf enum <code>JS_STRING = 1;</code>
*/
const JS_STRING = 1;
/**
* <pre>
* Use JavaScript numbers.
* </pre>
*
* <code>JS_NUMBER = 2;</code>
* Generated from protobuf enum <code>JS_NUMBER = 2;</code>
*/
const JS_NUMBER = 2;
}
......
......@@ -12,17 +12,15 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* <pre>
* The protocol compiler can output a FileDescriptorSet containing the .proto
* files it parses.
* </pre>
*
* Protobuf type <code>google.protobuf.FileDescriptorSet</code>
* Generated from protobuf message <code>google.protobuf.FileDescriptorSet</code>
*/
class FileDescriptorSet extends \Google\Protobuf\Internal\Message
{
/**
* <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
* Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
*/
private $file;
private $has_file = false;
......@@ -33,7 +31,8 @@ class FileDescriptorSet extends \Google\Protobuf\Internal\Message
}
/**
* <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
* Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getFile()
{
......@@ -41,7 +40,9 @@ class FileDescriptorSet extends \Google\Protobuf\Internal\Message
}
/**
* <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
* Generated from protobuf field <code>repeated .google.protobuf.FileDescriptorProto file = 1;</code>
* @param \Google\Protobuf\Internal\FileDescriptorProto[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setFile(&$var)
{
......
......@@ -5,36 +5,28 @@
namespace Google\Protobuf\Internal;
/**
* <pre>
* Generated classes can be optimized for speed or code size.
* </pre>
*
* Protobuf enum <code>google.protobuf.FileOptions.OptimizeMode</code>
* Protobuf enum <code>Google\Protobuf\Internal</code>
*/
class FileOptions_OptimizeMode
{
/**
* <pre>
* Generate complete code for parsing, serialization,
* </pre>
*
* <code>SPEED = 1;</code>
* Generated from protobuf enum <code>SPEED = 1;</code>
*/
const SPEED = 1;
/**
* <pre>
* etc.
* </pre>
*
* <code>CODE_SIZE = 2;</code>
* Generated from protobuf enum <code>CODE_SIZE = 2;</code>
*/
const CODE_SIZE = 2;
/**
* <pre>
* Generate code using MessageLite and the lite runtime.
* </pre>
*
* <code>LITE_RUNTIME = 3;</code>
* Generated from protobuf enum <code>LITE_RUNTIME = 3;</code>
*/
const LITE_RUNTIME = 3;
}
......
This diff is collapsed.
......@@ -45,8 +45,13 @@ class GPBUtil
$value = bcsub(0, $value);
}
$high = (int) bcdiv(bcadd($value, 1), 4294967296);
$high = bcdiv($value, 4294967296);
$low = bcmod($value, 4294967296);
if (bccomp($high, 2147483647) > 0) {
$high = (int) bcsub($high, 4294967296);
} else {
$high = (int) $high;
}
if (bccomp($low, 2147483647) > 0) {
$low = (int) bcsub($low, 4294967296);
} else {
......@@ -58,7 +63,7 @@ class GPBUtil
$low = ~$low;
$low++;
if (!$low) {
$high++;
$high = (int)($high + 1);
}
}
......@@ -70,15 +75,13 @@ class GPBUtil
public static function checkString(&$var, $check_utf8)
{
if (is_array($var) || is_object($var)) {
trigger_error("Expect string.", E_USER_ERROR);
return;
throw new \InvalidArgumentException("Expect string.");
}
if (!is_string($var)) {
$var = strval($var);
}
if ($check_utf8 && !preg_match('//u', $var)) {
trigger_error("Expect utf-8 encoding.", E_USER_ERROR);
return;
throw new \Exception("Expect utf-8 encoding.");
}
}
......@@ -92,7 +95,7 @@ class GPBUtil
if (is_numeric($var)) {
$var = intval($var);
} else {
trigger_error("Expect integer.", E_USER_ERROR);
throw new \Exception("Expect integer.");
}
}
......@@ -109,7 +112,7 @@ class GPBUtil
$var = (int) $var;
}
} else {
trigger_error("Expect integer.", E_USER_ERROR);
throw new \Exception("Expect integer.");
}
}
......@@ -119,10 +122,15 @@ class GPBUtil
if (PHP_INT_SIZE == 8) {
$var = intval($var);
} else {
$var = bcdiv($var, 1, 0);
if (is_float($var) ||
is_integer($var) ||
(is_string($var) &&
bccomp($var, "9223372036854774784") < 0)) {
$var = number_format($var, 0, ".", "");
}
}
} else {
trigger_error("Expect integer.", E_USER_ERROR);
throw new \Exception("Expect integer.");
}
}
......@@ -132,10 +140,10 @@ class GPBUtil
if (PHP_INT_SIZE == 8) {
$var = intval($var);
} else {
$var = bcdiv($var, 1, 0);
$var = number_format($var, 0, ".", "");
}
} else {
trigger_error("Expect integer.", E_USER_ERROR);
throw new \Exception("Expect integer.");
}
}
......@@ -144,7 +152,7 @@ class GPBUtil
if (is_float($var) || is_numeric($var)) {
$var = floatval($var);
} else {
trigger_error("Expect float.", E_USER_ERROR);
throw new \Exception("Expect float.");
}
}
......@@ -153,15 +161,14 @@ class GPBUtil
if (is_float($var) || is_numeric($var)) {
$var = floatval($var);
} else {
trigger_error("Expect float.", E_USER_ERROR);
throw new \Exception("Expect float.");
}
}
public static function checkBool(&$var)
{
if (is_array($var) || is_object($var)) {
trigger_error("Expect boolean.", E_USER_ERROR);
return;
throw new \Exception("Expect boolean.");
}
$var = boolval($var);
}
......@@ -169,14 +176,14 @@ class GPBUtil
public static function checkMessage(&$var, $klass)
{
if (!$var instanceof $klass && !is_null($var)) {
trigger_error("Expect message.", E_USER_ERROR);
throw new \Exception("Expect message.");
}
}
public static function checkRepeatedField(&$var, $type, $klass = null)
{
if (!$var instanceof RepeatedField && !is_array($var)) {
trigger_error("Expect array.", E_USER_ERROR);
throw new \Exception("Expect array.");
}
if (is_array($var)) {
$tmp = new RepeatedField($type, $klass);
......@@ -186,15 +193,13 @@ class GPBUtil
return $tmp;
} else {
if ($var->getType() != $type) {
trigger_error(
"Expect repeated field of different type.",
E_USER_ERROR);
throw new \Exception(
"Expect repeated field of different type.");
}
if ($var->getType() === GPBType::MESSAGE &&
$var->getClass() !== $klass) {
trigger_error(
"Expect repeated field of different message.",
E_USER_ERROR);
throw new \Exception(
"Expect repeated field of different message.");
}
return $var;
}
......@@ -203,7 +208,7 @@ class GPBUtil
public static function checkMapField(&$var, $key_type, $value_type, $klass = null)
{
if (!$var instanceof MapField && !is_array($var)) {
trigger_error("Expect dict.", E_USER_ERROR);
throw new \Exception("Expect dict.");
}
if (is_array($var)) {
$tmp = new MapField($key_type, $value_type, $klass);
......@@ -213,20 +218,15 @@ class GPBUtil
return $tmp;
} else {
if ($var->getKeyType() != $key_type) {
trigger_error(
"Expect map field of key type.",
E_USER_ERROR);
throw new \Exception("Expect map field of key type.");
}
if ($var->getValueType() != $value_type) {
trigger_error(
"Expect map field of value type.",
E_USER_ERROR);
throw new \Exception("Expect map field of value type.");
}
if ($var->getValueType() === GPBType::MESSAGE &&
$var->getValueClass() !== $klass) {
trigger_error(
"Expect map field of different value message.",
E_USER_ERROR);
throw new \Exception(
"Expect map field of different value message.");
}
return $var;
}
......@@ -328,7 +328,7 @@ class GPBUtil
$low = ~$low;
$low++;
if (!$low) {
$high++;
$high = (int) ($high + 1);
}
}
$result = bcadd(bcmul($high, 4294967296), $low);
......
......@@ -117,19 +117,12 @@ class GPBWire
// << decode <<
public static function zigZagEncode32($int32)
{
// Fill high 32 bits.
if (PHP_INT_SIZE === 8) {
$int32 |= ((($int32 << 32) >> 31) & (0xFFFFFFFF << 32));
if (PHP_INT_SIZE == 8) {
$trim_int32 = $int32 & 0xFFFFFFFF;
return (($trim_int32 << 1) ^ ($int32 << 32 >> 63)) & 0xFFFFFFFF;
} else {
return ($int32 << 1) ^ ($int32 >> 31);
}
$uint32 = ($int32 << 1) ^ ($int32 >> 31);
// Fill high 32 bits.
if (PHP_INT_SIZE === 8) {
$uint32 |= ((($uint32 << 32) >> 31) & (0xFFFFFFFF << 32));
}
return $uint32;
}
public static function zigZagDecode32($uint32)
......@@ -177,7 +170,11 @@ class GPBWire
public static function readInt64(&$input, &$value)
{
return $input->readVarint64($value);
$success = $input->readVarint64($value);
if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) {
$value = bcsub($value, "18446744073709551616");
}
return $success;
}
public static function readUint32(&$input, &$value)
......@@ -231,7 +228,11 @@ class GPBWire
public static function readSfixed64(&$input, &$value)
{
return $input->readLittleEndian64($value);
$success = $input->readLittleEndian64($value);
if (PHP_INT_SIZE == 4 && bccomp($value, "9223372036854775807") > 0) {
$value = bcsub($value, "18446744073709551616");
}
return $success;
}
public static function readFloat(&$input, &$value)
......@@ -298,7 +299,7 @@ class GPBWire
public static function writeInt32(&$output, $value)
{
return $output->writeVarint32($value);
return $output->writeVarint32($value, false);
}
public static function writeInt64(&$output, $value)
......@@ -308,7 +309,7 @@ class GPBWire
public static function writeUint32(&$output, $value)
{
return $output->writeVarint32($value);
return $output->writeVarint32($value, true);
}
public static function writeUint64(&$output, $value)
......@@ -319,7 +320,7 @@ class GPBWire
public static function writeSint32(&$output, $value)
{
$value = GPBWire::zigZagEncode32($value);
return $output->writeVarint64($value);
return $output->writeVarint32($value, true);
}
public static function writeSint64(&$output, $value)
......@@ -351,9 +352,9 @@ class GPBWire
public static function writeBool(&$output, $value)
{
if ($value) {
return $output->writeVarint32(1);
return $output->writeVarint32(1, true);
} else {
return $output->writeVarint32(0);
return $output->writeVarint32(0, true);
}
}
......@@ -377,7 +378,7 @@ class GPBWire
public static function writeBytes(&$output, $value)
{
$size = strlen($value);
if (!$output->writeVarint32($size)) {
if (!$output->writeVarint32($size, true)) {
return false;
}
return $output->writeRaw($value, $size);
......@@ -386,7 +387,7 @@ class GPBWire
public static function writeMessage(&$output, $value)
{
$size = $value->byteSize();
if (!$output->writeVarint32($size)) {
if (!$output->writeVarint32($size, true)) {
return false;
}
return $value->serializeToStream($output);
......@@ -442,7 +443,8 @@ class GPBWire
public static function varint64Size($value)
{
if (PHP_INT_SIZE == 4) {
if (bccomp($value, 0) < 0) {
if (bccomp($value, 0) < 0 ||
bccomp($value, "9223372036854775807") > 0) {
return 10;
}
if (bccomp($value, 1 << 7) < 0) {
......@@ -578,6 +580,9 @@ class GPBWire
}
break;
case GPBType::UINT32:
if (PHP_INT_SIZE === 8 && $value < 0) {
$value += 4294967296;
}
if (!GPBWire::writeUint32($output, $value)) {
return false;
}
......
<?php
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// https://developers.google.com/protocol-buffers/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace Google\Protobuf\Internal;
class GPBWireType
{
const VARINT = 0;
const FIXED64 = 1;
const LENGTH_DELIMITED = 2;
const START_GROUP = 3;
const END_GROUP = 4;
const FIXED32 = 5;
}
......@@ -12,23 +12,19 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* <pre>
* Describes the relationship between generated code and its original source
* file. A GeneratedCodeInfo message is associated with only one generated
* source file, but may contain references to different source .proto files.
* </pre>
*
* Protobuf type <code>google.protobuf.GeneratedCodeInfo</code>
* Generated from protobuf message <code>google.protobuf.GeneratedCodeInfo</code>
*/
class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message
{
/**
* <pre>
* An Annotation connects some span of text in generated code to an element
* of its generating .proto file.
* </pre>
*
* <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code>
* Generated from protobuf field <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code>
*/
private $annotation;
private $has_annotation = false;
......@@ -39,12 +35,11 @@ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* An Annotation connects some span of text in generated code to an element
* of its generating .proto file.
* </pre>
*
* <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code>
* Generated from protobuf field <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getAnnotation()
{
......@@ -52,12 +47,12 @@ class GeneratedCodeInfo extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* An Annotation connects some span of text in generated code to an element
* of its generating .proto file.
* </pre>
*
* <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code>
* Generated from protobuf field <code>repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1;</code>
* @param \Google\Protobuf\Internal\GeneratedCodeInfo_Annotation[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setAnnotation(&$var)
{
......
......@@ -12,47 +12,39 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* Protobuf type <code>google.protobuf.GeneratedCodeInfo.Annotation</code>
* Generated from protobuf message <code>google.protobuf.GeneratedCodeInfo.Annotation</code>
*/
class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
{
/**
* <pre>
* Identifies the element in the original source .proto file. This field
* is formatted the same as SourceCodeInfo.Location.path.
* </pre>
*
* <code>repeated int32 path = 1 [packed = true];</code>
* Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code>
*/
private $path;
private $has_path = false;
/**
* <pre>
* Identifies the filesystem path to the original source .proto.
* </pre>
*
* <code>optional string source_file = 2;</code>
* Generated from protobuf field <code>optional string source_file = 2;</code>
*/
private $source_file = '';
private $has_source_file = false;
/**
* <pre>
* Identifies the starting offset in bytes in the generated code
* that relates to the identified object.
* </pre>
*
* <code>optional int32 begin = 3;</code>
* Generated from protobuf field <code>optional int32 begin = 3;</code>
*/
private $begin = 0;
private $has_begin = false;
/**
* <pre>
* Identifies the ending offset in bytes in the generated code that
* relates to the identified offset. The end offset should be one past
* the last relevant byte (so the length of the text = end - begin).
* </pre>
*
* <code>optional int32 end = 4;</code>
* Generated from protobuf field <code>optional int32 end = 4;</code>
*/
private $end = 0;
private $has_end = false;
......@@ -63,12 +55,11 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Identifies the element in the original source .proto file. This field
* is formatted the same as SourceCodeInfo.Location.path.
* </pre>
*
* <code>repeated int32 path = 1 [packed = true];</code>
* Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code>
* @return \Google\Protobuf\Internal\RepeatedField
*/
public function getPath()
{
......@@ -76,12 +67,12 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Identifies the element in the original source .proto file. This field
* is formatted the same as SourceCodeInfo.Location.path.
* </pre>
*
* <code>repeated int32 path = 1 [packed = true];</code>
* Generated from protobuf field <code>repeated int32 path = 1 [packed = true];</code>
* @param int[]|\Google\Protobuf\Internal\RepeatedField $var
* @return $this
*/
public function setPath(&$var)
{
......@@ -98,11 +89,10 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Identifies the filesystem path to the original source .proto.
* </pre>
*
* <code>optional string source_file = 2;</code>
* Generated from protobuf field <code>optional string source_file = 2;</code>
* @return string
*/
public function getSourceFile()
{
......@@ -110,11 +100,11 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Identifies the filesystem path to the original source .proto.
* </pre>
*
* <code>optional string source_file = 2;</code>
* Generated from protobuf field <code>optional string source_file = 2;</code>
* @param string $var
* @return $this
*/
public function setSourceFile($var)
{
......@@ -131,12 +121,11 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Identifies the starting offset in bytes in the generated code
* that relates to the identified object.
* </pre>
*
* <code>optional int32 begin = 3;</code>
* Generated from protobuf field <code>optional int32 begin = 3;</code>
* @return int
*/
public function getBegin()
{
......@@ -144,12 +133,12 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Identifies the starting offset in bytes in the generated code
* that relates to the identified object.
* </pre>
*
* <code>optional int32 begin = 3;</code>
* Generated from protobuf field <code>optional int32 begin = 3;</code>
* @param int $var
* @return $this
*/
public function setBegin($var)
{
......@@ -166,13 +155,12 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Identifies the ending offset in bytes in the generated code that
* relates to the identified offset. The end offset should be one past
* the last relevant byte (so the length of the text = end - begin).
* </pre>
*
* <code>optional int32 end = 4;</code>
* Generated from protobuf field <code>optional int32 end = 4;</code>
* @return int
*/
public function getEnd()
{
......@@ -180,13 +168,13 @@ class GeneratedCodeInfo_Annotation extends \Google\Protobuf\Internal\Message
}
/**
* <pre>
* Identifies the ending offset in bytes in the generated code that
* relates to the identified offset. The end offset should be one past
* the last relevant byte (so the length of the text = end - begin).
* </pre>
*
* <code>optional int32 end = 4;</code>
* Generated from protobuf field <code>optional int32 end = 4;</code>
* @param int $var
* @return $this
*/
public function setEnd($var)
{
......
......@@ -205,7 +205,7 @@ class MapField implements \ArrayAccess, \IteratorAggregate, \Countable
*/
public function getIterator()
{
return new MapFieldIter($this->container);
return new MapFieldIter($this->container, $this->key_type);
}
/**
......
......@@ -54,11 +54,13 @@ class MapFieldIter implements \Iterator
*
* @param MapField The MapField instance for which this iterator is
* created.
* @param GPBType Map key type.
* @ignore
*/
public function __construct($container)
public function __construct($container, $key_type)
{
$this->container = $container;
$this->key_type = $key_type;
}
/**
......@@ -88,7 +90,13 @@ class MapFieldIter implements \Iterator
*/
public function key()
{
return key($this->container);
$key = key($this->container);
// PHP associative array stores bool as integer for key.
if ($this->key_type === GPBType::BOOL) {
return boolval($key);
} else {
return $key;
}
}
/**
......@@ -110,4 +118,4 @@ class MapFieldIter implements \Iterator
{
return key($this->container) !== null;
}
}
\ No newline at end of file
}
......@@ -5,34 +5,28 @@
namespace Google\Protobuf\Internal;
/**
* <pre>
* Is this method side-effect-free (or safe in HTTP parlance), or idempotent,
* or neither? HTTP based RPC implementation may choose GET verb for safe
* methods, and PUT verb for idempotent methods instead of the default POST.
* </pre>
*
* Protobuf enum <code>google.protobuf.MethodOptions.IdempotencyLevel</code>
* Protobuf enum <code>Google\Protobuf\Internal</code>
*/
class MethodOptions_IdempotencyLevel
{
/**
* <code>IDEMPOTENCY_UNKNOWN = 0;</code>
* Generated from protobuf enum <code>IDEMPOTENCY_UNKNOWN = 0;</code>
*/
const IDEMPOTENCY_UNKNOWN = 0;
/**
* <pre>
* implies idempotent
* </pre>
*
* <code>NO_SIDE_EFFECTS = 1;</code>
* Generated from protobuf enum <code>NO_SIDE_EFFECTS = 1;</code>
*/
const NO_SIDE_EFFECTS = 1;
/**
* <pre>
* idempotent, but may have side effects
* </pre>
*
* <code>IDEMPOTENT = 2;</code>
* Generated from protobuf enum <code>IDEMPOTENT = 2;</code>
*/
const IDEMPOTENT = 2;
}
......
......@@ -12,21 +12,19 @@ use Google\Protobuf\Internal\InputStream;
use Google\Protobuf\Internal\GPBUtil;
/**
* <pre>
* Describes a oneof.
* </pre>
*
* Protobuf type <code>google.protobuf.OneofDescriptorProto</code>
* Generated from protobuf message <code>google.protobuf.OneofDescriptorProto</code>
*/
class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
{
/**
* <code>optional string name = 1;</code>
* Generated from protobuf field <code>optional string name = 1;</code>
*/
private $name = '';
private $has_name = false;
/**
* <code>optional .google.protobuf.OneofOptions options = 2;</code>
* Generated from protobuf field <code>optional .google.protobuf.OneofOptions options = 2;</code>
*/
private $options = null;
private $has_options = false;
......@@ -37,7 +35,8 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional string name = 1;</code>
* Generated from protobuf field <code>optional string name = 1;</code>
* @return string
*/
public function getName()
{
......@@ -45,7 +44,9 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional string name = 1;</code>
* Generated from protobuf field <code>optional string name = 1;</code>
* @param string $var
* @return $this
*/
public function setName($var)
{
......@@ -62,7 +63,8 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional .google.protobuf.OneofOptions options = 2;</code>
* Generated from protobuf field <code>optional .google.protobuf.OneofOptions options = 2;</code>
* @return \Google\Protobuf\Internal\OneofOptions
*/
public function getOptions()
{
......@@ -70,7 +72,9 @@ class OneofDescriptorProto extends \Google\Protobuf\Internal\Message
}
/**
* <code>optional .google.protobuf.OneofOptions options = 2;</code>
* Generated from protobuf field <code>optional .google.protobuf.OneofOptions options = 2;</code>
* @param \Google\Protobuf\Internal\OneofOptions $var
* @return $this
*/
public function setOptions(&$var)
{
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -3,7 +3,7 @@
# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which
# phpunit` --bootstrap autoload.php tmp_test.php
#
gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php well_known_test.php
gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so `which phpunit` --bootstrap autoload.php encode_decode_test.php
#
# gdb --args php -dextension=../ext/google/protobuf/modules/protobuf.so memory_leak_test.php
#
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
FROM quay.io/pypa/manylinux1_x86_64
RUN yum install -y libtool
RUN /opt/python/cp27-cp27mu/bin/pip install twine
COPY protobuf_optimized_pip.sh /
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment