diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-02-08 10:27:54 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-08 10:27:54 -0800 |
commit | cba04b19e88dba2c13241b733bf7f595f1463082 (patch) | |
tree | da61ea725e19eadce400ae17df845e04f36bc608 /conformance/conformance_php.php | |
parent | c00274313d03a0a7f10e8f6473541faf3739353b (diff) | |
download | protobuf-cba04b19e88dba2c13241b733bf7f595f1463082.tar.gz protobuf-cba04b19e88dba2c13241b733bf7f595f1463082.tar.bz2 protobuf-cba04b19e88dba2c13241b733bf7f595f1463082.zip |
Implement json encoding decoding for php. (#2682)
Diffstat (limited to 'conformance/conformance_php.php')
-rwxr-xr-x | conformance/conformance_php.php | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/conformance/conformance_php.php b/conformance/conformance_php.php index c2314001..69001971 100755 --- a/conformance/conformance_php.php +++ b/conformance/conformance_php.php @@ -45,9 +45,19 @@ function doTest($request) $test_message = new \Protobuf_test_messages\Proto3\TestAllTypes(); $response = new \Conformance\ConformanceResponse(); if ($request->getPayload() == "protobuf_payload") { - $test_message->encode($request->getProtobufPayload()); + try { + $test_message->decode($request->getProtobufPayload()); + } catch (Exception $e) { + $response->setParseError($e->getMessage()); + return $response; + } } elseif ($request->getPayload() == "json_payload") { - // TODO(teboring): Implmement json decoding. + try { + $test_message->jsonDecode($request->getJsonPayload()); + } catch (Exception $e) { + $response->setParseError($e->getMessage()); + return $response; + } } else { trigger_error("Request didn't have payload.", E_USER_ERROR); } @@ -57,7 +67,7 @@ function doTest($request) } elseif ($request->getRequestedOutputFormat() == WireFormat::PROTOBUF) { $response->setProtobufPayload($test_message->encode()); } elseif ($request->getRequestedOutputFormat() == WireFormat::JSON) { - // TODO(teboring): Implmement json encoding. + $response->setJsonPayload($test_message->jsonEncode()); } return $response; |