Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
d2d4b403
Unverified
Commit
d2d4b403
authored
Oct 12, 2018
by
Paul Yang
Committed by
GitHub
Oct 12, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Sync upb for unknown fix (#5240)
parent
39df66e1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
219 additions
and
61 deletions
+219
-61
upb.c
php/ext/google/protobuf/upb.c
+95
-61
encode_decode_test.php
php/tests/encode_decode_test.php
+124
-0
No files found.
php/ext/google/protobuf/upb.c
View file @
d2d4b403
...
...
@@ -12659,6 +12659,9 @@ typedef struct {
* because |f| is the field in the *current* message (i.e., the map-entry
* message itself), not the parent's field that leads to this map. */
const
upb_fielddef
*
mapfield
;
/* True if the field to be parsed is unknown. */
bool
is_unknown_field
;
}
upb_jsonparser_frame
;
struct
upb_json_parser
{
...
...
@@ -13464,6 +13467,10 @@ static bool end_bool(upb_json_parser *p, bool val) {
start_value_object
(
p
,
VALUE_BOOLVALUE
);
}
if
(
p
->
top
->
is_unknown_field
)
{
return
true
;
}
if
(
!
parser_putbool
(
p
,
val
))
{
return
false
;
}
...
...
@@ -13570,6 +13577,7 @@ static bool start_stringval(upb_json_parser *p) {
inner
->
name_table
=
NULL
;
inner
->
is_map
=
false
;
inner
->
is_mapentry
=
false
;
inner
->
is_unknown_field
=
false
;
p
->
top
=
inner
;
if
(
upb_fielddef_type
(
p
->
top
->
f
)
==
UPB_TYPE_STRING
)
{
...
...
@@ -14061,6 +14069,7 @@ static bool handle_mapentry(upb_json_parser *p) {
inner
->
name_table
=
NULL
;
inner
->
mapfield
=
mapfield
;
inner
->
is_map
=
false
;
inner
->
is_unknown_field
=
false
;
/* Don't set this to true *yet* -- we reuse parsing handlers below to push
* the key field value to the sink, and these handlers will pop the frame
...
...
@@ -14091,6 +14100,8 @@ static bool end_membername(upb_json_parser *p) {
UPB_ASSERT
(
!
p
->
top
->
f
);
if
(
!
p
->
top
->
m
)
{
p
->
top
->
is_unknown_field
=
true
;
multipart_end
(
p
);
return
true
;
}
...
...
@@ -14107,6 +14118,7 @@ static bool end_membername(upb_json_parser *p) {
return
true
;
}
else
if
(
p
->
ignore_json_unknown
)
{
p
->
top
->
is_unknown_field
=
true
;
multipart_end
(
p
);
return
true
;
}
else
{
...
...
@@ -14138,10 +14150,11 @@ static void end_member(upb_json_parser *p) {
}
p
->
top
->
f
=
NULL
;
p
->
top
->
is_unknown_field
=
false
;
}
static
bool
start_subobject
(
upb_json_parser
*
p
)
{
if
(
p
->
top
->
f
==
NULL
)
{
if
(
p
->
top
->
is_unknown_field
)
{
upb_jsonparser_frame
*
inner
;
if
(
!
check_stack
(
p
))
return
false
;
...
...
@@ -14150,6 +14163,7 @@ static bool start_subobject(upb_json_parser *p) {
inner
->
f
=
NULL
;
inner
->
is_map
=
false
;
inner
->
is_mapentry
=
false
;
inner
->
is_unknown_field
=
false
;
p
->
top
=
inner
;
return
true
;
}
...
...
@@ -14171,6 +14185,7 @@ static bool start_subobject(upb_json_parser *p) {
inner
->
f
=
NULL
;
inner
->
is_map
=
true
;
inner
->
is_mapentry
=
false
;
inner
->
is_unknown_field
=
false
;
p
->
top
=
inner
;
return
true
;
...
...
@@ -14191,6 +14206,7 @@ static bool start_subobject(upb_json_parser *p) {
inner
->
f
=
NULL
;
inner
->
is_map
=
false
;
inner
->
is_mapentry
=
false
;
inner
->
is_unknown_field
=
false
;
p
->
top
=
inner
;
return
true
;
...
...
@@ -14290,7 +14306,18 @@ static bool start_array(upb_json_parser *p) {
start_listvalue_object
(
p
);
}
UPB_ASSERT
(
p
->
top
->
f
);
if
(
p
->
top
->
is_unknown_field
)
{
inner
=
p
->
top
+
1
;
inner
->
m
=
NULL
;
inner
->
name_table
=
NULL
;
inner
->
f
=
NULL
;
inner
->
is_map
=
false
;
inner
->
is_mapentry
=
false
;
inner
->
is_unknown_field
=
true
;
p
->
top
=
inner
;
return
true
;
}
if
(
!
upb_fielddef_isseq
(
p
->
top
->
f
))
{
upb_status_seterrf
(
&
p
->
status
,
...
...
@@ -14310,6 +14337,7 @@ static bool start_array(upb_json_parser *p) {
inner
->
f
=
p
->
top
->
f
;
inner
->
is_map
=
false
;
inner
->
is_mapentry
=
false
;
inner
->
is_unknown_field
=
false
;
p
->
top
=
inner
;
return
true
;
...
...
@@ -14321,6 +14349,11 @@ static void end_array(upb_json_parser *p) {
UPB_ASSERT
(
p
->
top
>
p
->
stack
);
p
->
top
--
;
if
(
p
->
top
->
is_unknown_field
)
{
return
;
}
sel
=
getsel_for_handlertype
(
p
,
UPB_HANDLER_ENDSEQ
);
upb_sink_endseq
(
&
p
->
top
->
sink
,
sel
);
...
...
@@ -14340,13 +14373,13 @@ static void end_array(upb_json_parser *p) {
}
static
void
start_object
(
upb_json_parser
*
p
)
{
if
(
!
p
->
top
->
is_map
)
{
if
(
!
p
->
top
->
is_map
&&
p
->
top
->
m
!=
NULL
)
{
upb_sink_startmsg
(
&
p
->
top
->
sink
);
}
}
static
void
end_object
(
upb_json_parser
*
p
)
{
if
(
!
p
->
top
->
is_map
)
{
if
(
!
p
->
top
->
is_map
&&
p
->
top
->
m
!=
NULL
)
{
upb_status
status
;
upb_status_clear
(
&
status
);
upb_sink_endmsg
(
&
p
->
top
->
sink
,
&
status
);
...
...
@@ -14458,7 +14491,7 @@ static void end_structvalue_object(upb_json_parser *p) {
}
static
bool
is_top_level
(
upb_json_parser
*
p
)
{
return
p
->
top
==
p
->
stack
&&
p
->
top
->
f
==
NULL
;
return
p
->
top
==
p
->
stack
&&
p
->
top
->
f
==
NULL
&&
!
p
->
top
->
is_unknown_field
;
}
static
bool
is_wellknown_msg
(
upb_json_parser
*
p
,
upb_wellknowntype_t
type
)
{
...
...
@@ -14521,11 +14554,11 @@ static bool is_string_wrapper_object(upb_json_parser *p) {
* final state once, when the closing '"' is seen. */
//#line 21
14
"upb/json/parser.rl"
//#line 21
47
"upb/json/parser.rl"
//#line
1983
"upb/json/parser.c"
//#line
2016
"upb/json/parser.c"
static
const
char
_json_actions
[]
=
{
0
,
1
,
0
,
1
,
1
,
1
,
3
,
1
,
4
,
1
,
6
,
1
,
7
,
1
,
8
,
1
,
...
...
@@ -14776,7 +14809,7 @@ static const int json_en_value_machine = 76;
static
const
int
json_en_main
=
1
;
//#line 21
17
"upb/json/parser.rl"
//#line 21
50
"upb/json/parser.rl"
size_t
parse
(
void
*
closure
,
const
void
*
hd
,
const
char
*
buf
,
size_t
size
,
const
upb_bufhandle
*
handle
)
{
...
...
@@ -14799,7 +14832,7 @@ size_t parse(void *closure, const void *hd, const char *buf, size_t size,
capture_resume
(
parser
,
buf
);
//#line 22
57
"upb/json/parser.c"
//#line 22
90
"upb/json/parser.c"
{
int
_klen
;
unsigned
int
_trans
;
...
...
@@ -14874,83 +14907,83 @@ _match:
switch
(
*
_acts
++
)
{
case
1
:
//#line
1988
"upb/json/parser.rl"
//#line
2021
"upb/json/parser.rl"
{
p
--
;
{
cs
=
stack
[
--
top
];
goto
_again
;}
}
break
;
case
2
:
//#line
1990
"upb/json/parser.rl"
//#line
2023
"upb/json/parser.rl"
{
p
--
;
{
stack
[
top
++
]
=
cs
;
cs
=
24
;
goto
_again
;}
}
break
;
case
3
:
//#line
1994
"upb/json/parser.rl"
//#line
2027
"upb/json/parser.rl"
{
start_text
(
parser
,
p
);
}
break
;
case
4
:
//#line
1995
"upb/json/parser.rl"
//#line
2028
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_text
(
parser
,
p
));
}
break
;
case
5
:
//#line 20
01
"upb/json/parser.rl"
//#line 20
34
"upb/json/parser.rl"
{
start_hex
(
parser
);
}
break
;
case
6
:
//#line 20
02
"upb/json/parser.rl"
//#line 20
35
"upb/json/parser.rl"
{
hexdigit
(
parser
,
p
);
}
break
;
case
7
:
//#line 20
03
"upb/json/parser.rl"
//#line 20
36
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_hex
(
parser
));
}
break
;
case
8
:
//#line 20
09
"upb/json/parser.rl"
//#line 20
42
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
escape
(
parser
,
p
));
}
break
;
case
9
:
//#line 20
15
"upb/json/parser.rl"
//#line 20
48
"upb/json/parser.rl"
{
p
--
;
{
cs
=
stack
[
--
top
];
goto
_again
;}
}
break
;
case
10
:
//#line 20
27
"upb/json/parser.rl"
//#line 20
60
"upb/json/parser.rl"
{
start_duration_base
(
parser
,
p
);
}
break
;
case
11
:
//#line 20
28
"upb/json/parser.rl"
//#line 20
61
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_duration_base
(
parser
,
p
));
}
break
;
case
12
:
//#line 20
30
"upb/json/parser.rl"
//#line 20
63
"upb/json/parser.rl"
{
p
--
;
{
cs
=
stack
[
--
top
];
goto
_again
;}
}
break
;
case
13
:
//#line 20
35
"upb/json/parser.rl"
//#line 20
68
"upb/json/parser.rl"
{
start_timestamp_base
(
parser
,
p
);
}
break
;
case
14
:
//#line 20
36
"upb/json/parser.rl"
//#line 20
69
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_timestamp_base
(
parser
,
p
));
}
break
;
case
15
:
//#line 20
38
"upb/json/parser.rl"
//#line 20
71
"upb/json/parser.rl"
{
start_timestamp_fraction
(
parser
,
p
);
}
break
;
case
16
:
//#line 20
39
"upb/json/parser.rl"
//#line 20
72
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_timestamp_fraction
(
parser
,
p
));
}
break
;
case
17
:
//#line 20
41
"upb/json/parser.rl"
//#line 20
74
"upb/json/parser.rl"
{
start_timestamp_zone
(
parser
,
p
);
}
break
;
case
18
:
//#line 20
42
"upb/json/parser.rl"
//#line 20
75
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_timestamp_zone
(
parser
,
p
));
}
break
;
case
19
:
//#line 20
44
"upb/json/parser.rl"
//#line 20
77
"upb/json/parser.rl"
{
p
--
;
{
cs
=
stack
[
--
top
];
goto
_again
;}
}
break
;
case
20
:
//#line 20
49
"upb/json/parser.rl"
//#line 20
82
"upb/json/parser.rl"
{
if
(
is_wellknown_msg
(
parser
,
UPB_WELLKNOWN_TIMESTAMP
))
{
{
stack
[
top
++
]
=
cs
;
cs
=
48
;
goto
_again
;}
...
...
@@ -14962,78 +14995,78 @@ _match:
}
break
;
case
21
:
//#line 20
60
"upb/json/parser.rl"
//#line 20
93
"upb/json/parser.rl"
{
p
--
;
{
stack
[
top
++
]
=
cs
;
cs
=
76
;
goto
_again
;}
}
break
;
case
22
:
//#line 20
65
"upb/json/parser.rl"
//#line 20
98
"upb/json/parser.rl"
{
start_member
(
parser
);
}
break
;
case
23
:
//#line 20
66
"upb/json/parser.rl"
//#line 20
99
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_membername
(
parser
));
}
break
;
case
24
:
//#line 2
069
"upb/json/parser.rl"
//#line 2
102
"upb/json/parser.rl"
{
end_member
(
parser
);
}
break
;
case
25
:
//#line 2
075
"upb/json/parser.rl"
//#line 2
108
"upb/json/parser.rl"
{
start_object
(
parser
);
}
break
;
case
26
:
//#line 2
078
"upb/json/parser.rl"
//#line 2
111
"upb/json/parser.rl"
{
end_object
(
parser
);
}
break
;
case
27
:
//#line 2
084
"upb/json/parser.rl"
//#line 2
117
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
start_array
(
parser
));
}
break
;
case
28
:
//#line 2
088
"upb/json/parser.rl"
//#line 2
121
"upb/json/parser.rl"
{
end_array
(
parser
);
}
break
;
case
29
:
//#line 2
093
"upb/json/parser.rl"
//#line 2
126
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
start_number
(
parser
,
p
));
}
break
;
case
30
:
//#line 2
094
"upb/json/parser.rl"
//#line 2
127
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_number
(
parser
,
p
));
}
break
;
case
31
:
//#line 2
096
"upb/json/parser.rl"
//#line 2
129
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
start_stringval
(
parser
));
}
break
;
case
32
:
//#line 2
097
"upb/json/parser.rl"
//#line 2
130
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_stringval
(
parser
));
}
break
;
case
33
:
//#line 2
099
"upb/json/parser.rl"
//#line 2
132
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_bool
(
parser
,
true
));
}
break
;
case
34
:
//#line 21
01
"upb/json/parser.rl"
//#line 21
34
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_bool
(
parser
,
false
));
}
break
;
case
35
:
//#line 21
03
"upb/json/parser.rl"
//#line 21
36
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_null
(
parser
));
}
break
;
case
36
:
//#line 21
05
"upb/json/parser.rl"
//#line 21
38
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
start_subobject_full
(
parser
));
}
break
;
case
37
:
//#line 21
06
"upb/json/parser.rl"
//#line 21
39
"upb/json/parser.rl"
{
end_subobject_full
(
parser
);
}
break
;
case
38
:
//#line 21
11
"upb/json/parser.rl"
//#line 21
44
"upb/json/parser.rl"
{
p
--
;
{
cs
=
stack
[
--
top
];
goto
_again
;}
}
break
;
//#line 2
491
"upb/json/parser.c"
//#line 2
524
"upb/json/parser.c"
}
}
...
...
@@ -15050,34 +15083,34 @@ _again:
while
(
__nacts
--
>
0
)
{
switch
(
*
__acts
++
)
{
case
0
:
//#line
1986
"upb/json/parser.rl"
//#line
2019
"upb/json/parser.rl"
{
p
--
;
{
cs
=
stack
[
--
top
];
goto
_again
;}
}
break
;
case
26
:
//#line 2
078
"upb/json/parser.rl"
//#line 2
111
"upb/json/parser.rl"
{
end_object
(
parser
);
}
break
;
case
30
:
//#line 2
094
"upb/json/parser.rl"
//#line 2
127
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_number
(
parser
,
p
));
}
break
;
case
33
:
//#line 2
099
"upb/json/parser.rl"
//#line 2
132
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_bool
(
parser
,
true
));
}
break
;
case
34
:
//#line 21
01
"upb/json/parser.rl"
//#line 21
34
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_bool
(
parser
,
false
));
}
break
;
case
35
:
//#line 21
03
"upb/json/parser.rl"
//#line 21
36
"upb/json/parser.rl"
{
CHECK_RETURN_TOP
(
end_null
(
parser
));
}
break
;
case
37
:
//#line 21
06
"upb/json/parser.rl"
//#line 21
39
"upb/json/parser.rl"
{
end_subobject_full
(
parser
);
}
break
;
//#line 25
35
"upb/json/parser.c"
//#line 25
68
"upb/json/parser.c"
}
}
}
...
...
@@ -15085,7 +15118,7 @@ _again:
_out:
{}
}
//#line 21
39
"upb/json/parser.rl"
//#line 21
72
"upb/json/parser.rl"
if
(
p
!=
pe
)
{
upb_status_seterrf
(
&
parser
->
status
,
"Parse error at '%.*s'
\n
"
,
pe
-
p
,
p
);
...
...
@@ -15117,9 +15150,9 @@ bool end(void *closure, const void *hd) {
parse
(
parser
,
hd
,
&
eof_ch
,
0
,
NULL
);
return
parser
->
current_state
>=
//#line 2
575
"upb/json/parser.c"
//#line 2
608
"upb/json/parser.c"
105
//#line 2
169
"upb/json/parser.rl"
//#line 2
202
"upb/json/parser.rl"
;
}
...
...
@@ -15131,16 +15164,17 @@ static void json_parser_reset(upb_json_parser *p) {
p
->
top
->
f
=
NULL
;
p
->
top
->
is_map
=
false
;
p
->
top
->
is_mapentry
=
false
;
p
->
top
->
is_unknown_field
=
false
;
/* Emit Ragel initialization of the parser. */
//#line 2
592
"upb/json/parser.c"
//#line 2
626
"upb/json/parser.c"
{
cs
=
json_start
;
top
=
0
;
}
//#line 2
183
"upb/json/parser.rl"
//#line 2
217
"upb/json/parser.rl"
p
->
current_state
=
cs
;
p
->
parser_top
=
top
;
accumulate_clear
(
p
);
...
...
php/tests/encode_decode_test.php
View file @
d2d4b403
...
...
@@ -23,6 +23,7 @@ use Google\Protobuf\BytesValue;
use
Google\Protobuf\Value
;
use
Google\Protobuf\ListValue
;
use
Google\Protobuf\Struct
;
use
Google\Protobuf\GPBEmpty
;
class
EncodeDecodeTest
extends
TestBase
{
...
...
@@ -660,6 +661,129 @@ class EncodeDecodeTest extends TestBase
$this
->
assertSame
(
"9a0400"
,
bin2hex
(
$to
));
}
public
function
testJsonUnknown
()
{
// Test unknown number
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":1,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown bool
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":true,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown string
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":
\"
abc
\"
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown null
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":null,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown number array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[1],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown bool array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[true],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown string array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[
\"
a
\"
],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown null array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[null],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown array array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[[]],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown object array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":[{
}
],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown double value array
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":[1, 2],
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown number object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":1
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown bool object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":true
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown string object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":\"a\"
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown null object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":null
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown array object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":[]
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown object object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"
{
\"unknown\":{\"a\":{}
}
,
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
// Test unknown double value object
$m
=
new
TestMessage
();
$m
->
mergeFromJsonString
(
"{\"
unknown
\
":{\"
a
\
":1,
\"
b
\"
:1},
\"
optionalInt32
\"
:1}"
,
true
);
$this
->
assertSame
(
1
,
$m
->
getOptionalInt32
());
}
public
function
testJsonEncode
()
{
$from
=
new
TestMessage
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment