Change int64 json encoding to be string for php and ruby (#6251)

* Change int64 json encoding to be string for php and ruby

* Fix ruby test

* Sync upb change
This commit is contained in:
Paul Yang 2019-06-17 13:14:27 -07:00 committed by GitHub
parent 444354f41a
commit 640423f157
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 64 additions and 36 deletions

View File

@ -6,7 +6,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter
Recommended.Proto3.JsonInput.Int64FieldBeString.Validator
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.OneofZeroBytes.JsonOutput
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull
@ -17,7 +16,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate
Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator
Recommended.Proto3.ProtobufInput.OneofZeroBytes.JsonOutput
Required.DurationProtoInputTooLarge.JsonOutput
Required.DurationProtoInputTooSmall.JsonOutput

View File

@ -6,7 +6,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.FieldMaskInvalidCharacter
Recommended.Proto3.JsonInput.Int64FieldBeString.Validator
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull
Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull
@ -16,7 +15,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate
Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator
Required.DurationProtoInputTooLarge.JsonOutput
Required.DurationProtoInputTooSmall.JsonOutput
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput

View File

@ -5,7 +5,6 @@ Recommended.Proto3.JsonInput.BytesFieldBase64Url.JsonOutput
Recommended.Proto3.JsonInput.BytesFieldBase64Url.ProtobufOutput
Recommended.Proto3.JsonInput.DurationHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.DurationHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.Int64FieldBeString.Validator
Recommended.Proto3.JsonInput.MapFieldValueIsNull
Recommended.Proto3.JsonInput.RepeatedFieldMessageElementIsNull
Recommended.Proto3.JsonInput.RepeatedFieldPrimitiveElementIsNull
@ -15,7 +14,6 @@ Recommended.Proto3.JsonInput.StringFieldUnpairedHighSurrogate
Recommended.Proto3.JsonInput.StringFieldUnpairedLowSurrogate
Recommended.Proto3.JsonInput.TimestampHas3FractionalDigits.Validator
Recommended.Proto3.JsonInput.TimestampHas6FractionalDigits.Validator
Recommended.Proto3.JsonInput.Uint64FieldBeString.Validator
Required.DurationProtoInputTooLarge.JsonOutput
Required.DurationProtoInputTooSmall.JsonOutput
Required.Proto3.JsonInput.DoubleFieldMaxNegativeValue.JsonOutput

View File

@ -12431,18 +12431,32 @@ static size_t fmt_bool(bool val, char* buf, size_t length) {
return n;
}
static size_t fmt_int64(long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%ld", val);
static size_t fmt_int64_as_number(long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%lld", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_uint64(unsigned long long val, char* buf, size_t length) {
static size_t fmt_uint64_as_number(
unsigned long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%llu", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_int64_as_string(long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "\"%lld\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_uint64_as_string(
unsigned long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "\"%llu\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
/* Print a map key given a field name. Called by scalar field handlers and by
* startseq for repeated fields. */
static bool putkey(void *closure, const void *handler_data) {
@ -12486,8 +12500,11 @@ static bool putkey(void *closure, const void *handler_data) {
static bool putmapkey_##type(void *closure, const void *handler_data, \
type val) { \
upb_json_printer *p = closure; \
char data[64]; \
size_t length = fmt_func(val, data, sizeof(data)); \
UPB_UNUSED(handler_data); \
print_data(p, "\"", 1); \
CHK(put##type(closure, handler_data, val)); \
print_data(p, data, length); \
print_data(p, "\":", 2); \
return true; \
}
@ -12495,17 +12512,17 @@ static bool putkey(void *closure, const void *handler_data) {
TYPE_HANDLERS(double, fmt_double)
TYPE_HANDLERS(float, fmt_float)
TYPE_HANDLERS(bool, fmt_bool)
TYPE_HANDLERS(int32_t, fmt_int64)
TYPE_HANDLERS(uint32_t, fmt_int64)
TYPE_HANDLERS(int64_t, fmt_int64)
TYPE_HANDLERS(uint64_t, fmt_uint64)
TYPE_HANDLERS(int32_t, fmt_int64_as_number)
TYPE_HANDLERS(uint32_t, fmt_int64_as_number)
TYPE_HANDLERS(int64_t, fmt_int64_as_string)
TYPE_HANDLERS(uint64_t, fmt_uint64_as_string)
/* double and float are not allowed to be map keys. */
TYPE_HANDLERS_MAPKEY(bool, fmt_bool)
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64)
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64_as_number)
#undef TYPE_HANDLERS
#undef TYPE_HANDLERS_MAPKEY

View File

@ -16289,18 +16289,32 @@ static size_t fmt_bool(bool val, char* buf, size_t length) {
return n;
}
static size_t fmt_int64(long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%ld", val);
static size_t fmt_int64_as_number(long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%lld", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_uint64(unsigned long long val, char* buf, size_t length) {
static size_t fmt_uint64_as_number(
unsigned long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "%llu", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_int64_as_string(long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "\"%lld\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
static size_t fmt_uint64_as_string(
unsigned long long val, char* buf, size_t length) {
size_t n = _upb_snprintf(buf, length, "\"%llu\"", val);
CHKLENGTH(n > 0 && n < length);
return n;
}
/* Print a map key given a field name. Called by scalar field handlers and by
* startseq for repeated fields. */
static bool putkey(void *closure, const void *handler_data) {
@ -16344,8 +16358,11 @@ static bool putkey(void *closure, const void *handler_data) {
static bool putmapkey_##type(void *closure, const void *handler_data, \
type val) { \
upb_json_printer *p = closure; \
char data[64]; \
size_t length = fmt_func(val, data, sizeof(data)); \
UPB_UNUSED(handler_data); \
print_data(p, "\"", 1); \
CHK(put##type(closure, handler_data, val)); \
print_data(p, data, length); \
print_data(p, "\":", 2); \
return true; \
}
@ -16353,17 +16370,17 @@ static bool putkey(void *closure, const void *handler_data) {
TYPE_HANDLERS(double, fmt_double)
TYPE_HANDLERS(float, fmt_float)
TYPE_HANDLERS(bool, fmt_bool)
TYPE_HANDLERS(int32_t, fmt_int64)
TYPE_HANDLERS(uint32_t, fmt_int64)
TYPE_HANDLERS(int64_t, fmt_int64)
TYPE_HANDLERS(uint64_t, fmt_uint64)
TYPE_HANDLERS(int32_t, fmt_int64_as_number)
TYPE_HANDLERS(uint32_t, fmt_int64_as_number)
TYPE_HANDLERS(int64_t, fmt_int64_as_string)
TYPE_HANDLERS(uint64_t, fmt_uint64_as_string)
/* double and float are not allowed to be map keys. */
TYPE_HANDLERS_MAPKEY(bool, fmt_bool)
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64)
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64)
TYPE_HANDLERS_MAPKEY(int32_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(uint32_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(int64_t, fmt_int64_as_number)
TYPE_HANDLERS_MAPKEY(uint64_t, fmt_uint64_as_number)
#undef TYPE_HANDLERS
#undef TYPE_HANDLERS_MAPKEY

View File

@ -1108,9 +1108,9 @@ module CommonTests
expected = {
optionalInt32: 0,
optionalInt64: 0,
optionalInt64: "0",
optionalUint32: 0,
optionalUint64: 0,
optionalUint64: "0",
optionalBool: false,
optionalFloat: 0,
optionalDouble: 0,
@ -1142,9 +1142,9 @@ module CommonTests
expected = {
optionalInt32: 0,
optionalInt64: 0,
optionalInt64: "0",
optionalUint32: 0,
optionalUint64: 0,
optionalUint64: "0",
optionalBool: false,
optionalFloat: 0,
optionalDouble: 0,
@ -1177,9 +1177,9 @@ module CommonTests
expected = {
optionalInt32: 0,
optionalInt64: 0,
optionalInt64: "0",
optionalUint32: 0,
optionalUint64: 0,
optionalUint64: "0",
optionalBool: false,
optionalFloat: 0,
optionalDouble: 0,