From 66b50e6e956adac1ec45ab6d3fa13c89211bbba5 Mon Sep 17 00:00:00 2001 From: David Snider Date: Sat, 16 Feb 2019 09:53:30 -0800 Subject: [PATCH] new fixtures Summary: For the differences between this and the next item Reviewed By: yfeldblum Differential Revision: D14111355 fbshipit-source-id: d4750c416f35447dd6269e1e1535e606bdda97db --- .../test/fixtures/hack-struct-keys/cmd | 1 + .../hack-struct-keys/gen-hack/Baz.php | 294 ++++++++++++++++++ .../gen-hack/module_types.php | 113 +++++++ .../hack-struct-keys/src/module.thrift | 16 + 4 files changed, 424 insertions(+) create mode 100644 thrift/compiler/test/fixtures/hack-struct-keys/cmd create mode 100644 thrift/compiler/test/fixtures/hack-struct-keys/gen-hack/Baz.php create mode 100644 thrift/compiler/test/fixtures/hack-struct-keys/gen-hack/module_types.php create mode 100644 thrift/compiler/test/fixtures/hack-struct-keys/src/module.thrift diff --git a/thrift/compiler/test/fixtures/hack-struct-keys/cmd b/thrift/compiler/test/fixtures/hack-struct-keys/cmd new file mode 100644 index 00000000000..28dd6e67e79 --- /dev/null +++ b/thrift/compiler/test/fixtures/hack-struct-keys/cmd @@ -0,0 +1 @@ +hack src/module.thrift diff --git a/thrift/compiler/test/fixtures/hack-struct-keys/gen-hack/Baz.php b/thrift/compiler/test/fixtures/hack-struct-keys/gen-hack/Baz.php new file mode 100644 index 00000000000..ed4d01156ba --- /dev/null +++ b/thrift/compiler/test/fixtures/hack-struct-keys/gen-hack/Baz.php @@ -0,0 +1,294 @@ + a, + * 2: list b, + * 3: map c); + */ + public function qux(Set $a, \HH\KeyedContainer $b, \HH\KeyedContainer $c): Awaitable; +} + +/** + * Original thrift service:- + * Baz + */ +interface BazIf extends \IThriftSyncIf { + /** + * Original thrift definition:- + * string + * qux(1: set a, + * 2: list b, + * 3: map c); + */ + public function qux(Set $a, \HH\KeyedContainer $b, \HH\KeyedContainer $c): string; +} + +/** + * Original thrift service:- + * Baz + */ +trait BazClientBase { + require extends \ThriftClientBase; + + protected function sendImpl_qux(Set $a, \HH\KeyedContainer $b, \HH\KeyedContainer $c): int { + $currentseqid = $this->getNextSequenceID(); + $args = new Baz_qux_args( + $a, + new Vector($b), + new Map($c), + ); + try { + $this->eventHandler_->preSend('qux', $args, $currentseqid); + if ($this->output_ is \TBinaryProtocolAccelerated) + { + \thrift_protocol_write_binary($this->output_, 'qux', \TMessageType::CALL, $args, $currentseqid, $this->output_->isStrictWrite(), false); + } + else if ($this->output_ is \TCompactProtocolAccelerated) + { + \thrift_protocol_write_compact($this->output_, 'qux', \TMessageType::CALL, $args, $currentseqid, false); + } + else + { + $this->output_->writeMessageBegin('qux', \TMessageType::CALL, $currentseqid); + $args->write($this->output_); + $this->output_->writeMessageEnd(); + $this->output_->getTransport()->flush(); + } + } catch (\THandlerShortCircuitException $ex) { + switch ($ex->resultType) { + case \THandlerShortCircuitException::R_EXPECTED_EX: + case \THandlerShortCircuitException::R_UNEXPECTED_EX: + $this->eventHandler_->sendError('qux', $args, $currentseqid, $ex->result); + throw $ex->result; + case \THandlerShortCircuitException::R_SUCCESS: + default: + $this->eventHandler_->postSend('qux', $args, $currentseqid); + return $currentseqid; + } + } catch (\Exception $ex) { + $this->eventHandler_->sendError('qux', $args, $currentseqid, $ex); + throw $ex; + } + $this->eventHandler_->postSend('qux', $args, $currentseqid); + return $currentseqid; + } + + protected function recvImpl_qux(?int $expectedsequenceid = null): string { + try { + $this->eventHandler_->preRecv('qux', $expectedsequenceid); + if ($this->input_ is \TBinaryProtocolAccelerated) { + $result = \thrift_protocol_read_binary($this->input_, 'Baz_qux_result', $this->input_->isStrictRead()); + } else if ($this->input_ is \TCompactProtocolAccelerated) + { + $result = \thrift_protocol_read_compact($this->input_, 'Baz_qux_result'); + } + else + { + $rseqid = 0; + $fname = ''; + $mtype = 0; + + $this->input_->readMessageBegin(&$fname, &$mtype, &$rseqid); + if ($mtype == \TMessageType::EXCEPTION) { + $x = new \TApplicationException(); + $x->read($this->input_); + $this->input_->readMessageEnd(); + throw $x; + } + $result = new Baz_qux_result(); + $result->read($this->input_); + $this->input_->readMessageEnd(); + if ($expectedsequenceid !== null && ($rseqid != $expectedsequenceid)) { + throw new \TProtocolException("qux failed: sequence id is out of order"); + } + } + } catch (\THandlerShortCircuitException $ex) { + switch ($ex->resultType) { + case \THandlerShortCircuitException::R_EXPECTED_EX: + $this->eventHandler_->recvException('qux', $expectedsequenceid, $ex->result); + throw $ex->result; + case \THandlerShortCircuitException::R_UNEXPECTED_EX: + $this->eventHandler_->recvError('qux', $expectedsequenceid, $ex->result); + throw $ex->result; + case \THandlerShortCircuitException::R_SUCCESS: + default: + $this->eventHandler_->postRecv('qux', $expectedsequenceid, $ex->result); + return $ex->result; + } + } catch (\Exception $ex) { + $this->eventHandler_->recvError('qux', $expectedsequenceid, $ex); + throw $ex; + } + if ($result->success !== null) { + $success = $result->success; + $this->eventHandler_->postRecv('qux', $expectedsequenceid, $success); + return $success; + } + $x = new \TApplicationException("qux failed: unknown result", \TApplicationException::MISSING_RESULT); + $this->eventHandler_->recvError('qux', $expectedsequenceid, $x); + throw $x; + } + +} + +class BazAsyncClient extends \ThriftClientBase implements BazAsyncIf { + use BazClientBase; + + /** + * Original thrift definition:- + * string + * qux(1: set a, + * 2: list b, + * 3: map c); + */ + public async function qux(Set $a, \HH\KeyedContainer $b, \HH\KeyedContainer $c): Awaitable { + $currentseqid = $this->sendImpl_qux($a, $b, $c); + await $this->asyncHandler_->genWait($currentseqid); + return $this->recvImpl_qux($currentseqid); + } + +} + +class BazClient extends \ThriftClientBase implements BazIf { + use BazClientBase; + + <<__Deprecated('use gen_qux()')>> + public function qux(Set $a, \HH\KeyedContainer $b, \HH\KeyedContainer $c): string { + $currentseqid = $this->sendImpl_qux($a, $b, $c); + return $this->recvImpl_qux($currentseqid); + } + + /** + * Original thrift definition:- + * string + * qux(1: set a, + * 2: list b, + * 3: map c); + */ + public async function gen_qux(Set $a, \HH\KeyedContainer $b, \HH\KeyedContainer $c): Awaitable { + $currentseqid = $this->sendImpl_qux($a, $b, $c); + await $this->asyncHandler_->genWait($currentseqid); + return $this->recvImpl_qux($currentseqid); + } + + /* send and recv functions */ + public function send_qux(Set $a, \HH\KeyedContainer $b, \HH\KeyedContainer $c): int { + return $this->sendImpl_qux($a, $b, $c); + } + public function recv_qux(?int $expectedsequenceid = null): string { + return $this->recvImpl_qux($expectedsequenceid); + } +} + +// HELPER FUNCTIONS AND STRUCTURES + +class Baz_qux_args implements \IThriftStruct { + use \ThriftSerializationTrait; + + public static dict> $_TSPEC = dict[ + 1 => dict[ + 'var' => 'a', + 'type' => \TType::SET, + 'etype' => \TType::STRUCT, + 'elem' => dict[ + 'type' => \TType::STRUCT, + 'class' => 'Foo', + ], + 'format' => 'collection', + ], + 2 => dict[ + 'var' => 'b', + 'type' => \TType::LST, + 'etype' => \TType::STRUCT, + 'elem' => dict[ + 'type' => \TType::STRUCT, + 'class' => 'Bar', + ], + 'format' => 'collection', + ], + 3 => dict[ + 'var' => 'c', + 'type' => \TType::MAP, + 'ktype' => \TType::STRUCT, + 'vtype' => \TType::STRING, + 'key' => dict[ + 'type' => \TType::STRUCT, + 'class' => 'Foo', + ], + 'val' => dict[ + 'type' => \TType::STRING, + ], + 'format' => 'collection', + ], + ]; + public static Map $_TFIELDMAP = Map { + 'a' => 1, + 'b' => 2, + 'c' => 3, + }; + const int STRUCTURAL_ID = 1160460043765273624; + public Set $a; + public Vector $b; + public Map $c; + + public function __construct(?Set $a = null, ?Vector $b = null, ?Map $c = null ) { + if ($a === null) { + $this->a = Set {}; + } else { + $this->a = $a; + } + if ($b === null) { + $this->b = Vector {}; + } else { + $this->b = $b; + } + if ($c === null) { + $this->c = Map {}; + } else { + $this->c = $c; + } + } + + public function getName(): string { + return 'Baz_qux_args'; + } + +} + +class Baz_qux_result implements \IThriftStruct { + use \ThriftSerializationTrait; + + public static dict> $_TSPEC = dict[ + 0 => dict[ + 'var' => 'success', + 'type' => \TType::STRING, + ], + ]; + public static Map $_TFIELDMAP = Map { + 'success' => 0, + }; + const int STRUCTURAL_ID = 1365128170602685579; + public ?string $success; + + public function __construct(?string $success = null ) { + } + + public function getName(): string { + return 'Baz_qux_result'; + } + +} + diff --git a/thrift/compiler/test/fixtures/hack-struct-keys/gen-hack/module_types.php b/thrift/compiler/test/fixtures/hack-struct-keys/gen-hack/module_types.php new file mode 100644 index 00000000000..37ca63b44fb --- /dev/null +++ b/thrift/compiler/test/fixtures/hack-struct-keys/gen-hack/module_types.php @@ -0,0 +1,113 @@ +> $_TSPEC = dict[ + 1 => dict[ + 'var' => 'fiels', + 'type' => \TType::I32, + ], + ]; + public static Map $_TFIELDMAP = Map { + 'fiels' => 1, + }; + const int STRUCTURAL_ID = 3168813896074353984; + /** + * Original thrift field:- + * 1: i32 fiels + */ + public int $fiels; + + public function __construct(?int $fiels = null ) { + if ($fiels === null) { + $this->fiels = 0; + } else { + $this->fiels = $fiels; + } + } + + public function getName(): string { + return 'Foo'; + } + +} + +/** + * Original thrift struct:- + * Bar + */ +class Bar implements \IThriftStruct { + use \ThriftSerializationTrait; + + public static dict> $_TSPEC = dict[ + 1 => dict[ + 'var' => 'a', + 'type' => \TType::SET, + 'etype' => \TType::STRUCT, + 'elem' => dict[ + 'type' => \TType::STRUCT, + 'class' => 'Foo', + ], + 'format' => 'collection', + ], + 2 => dict[ + 'var' => 'b', + 'type' => \TType::MAP, + 'ktype' => \TType::STRUCT, + 'vtype' => \TType::I32, + 'key' => dict[ + 'type' => \TType::STRUCT, + 'class' => 'Foo', + ], + 'val' => dict[ + 'type' => \TType::I32, + ], + 'format' => 'collection', + ], + ]; + public static Map $_TFIELDMAP = Map { + 'a' => 1, + 'b' => 2, + }; + const int STRUCTURAL_ID = 5283012534631553068; + /** + * Original thrift field:- + * 1: set a + */ + public Set $a; + /** + * Original thrift field:- + * 2: map b + */ + public Map $b; + + public function __construct(?Set $a = null, ?Map $b = null ) { + if ($a === null) { + $this->a = Set {}; + } else { + $this->a = $a; + } + if ($b === null) { + $this->b = Map {}; + } else { + $this->b = $b; + } + } + + public function getName(): string { + return 'Bar'; + } + +} + diff --git a/thrift/compiler/test/fixtures/hack-struct-keys/src/module.thrift b/thrift/compiler/test/fixtures/hack-struct-keys/src/module.thrift new file mode 100644 index 00000000000..cff462755b8 --- /dev/null +++ b/thrift/compiler/test/fixtures/hack-struct-keys/src/module.thrift @@ -0,0 +1,16 @@ +struct Foo { + 1: i32 fiels; +} + +struct Bar { + 1: set a; + 2: map b; +} + +service Baz { + string qux( + 1: set a, + 2: list b, + 3: map c, + ); +}