Skip to content

Commit 7be0b87

Browse files
authored
[TL2] step 0: added RpcFunctionFetcher (#1407)
1 parent 89033ad commit 7be0b87

File tree

8 files changed

+129
-0
lines changed

8 files changed

+129
-0
lines changed

builtin-functions/kphp-full/_functions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ require_once __DIR__ . '/kphp_toggles.txt';
1818
require_once __DIR__ . '/kphp_tracing.txt';
1919
require_once __DIR__ . '/uberh3.txt';
2020
require_once __DIR__ . '/spl.txt';
21+
require_once __DIR__ . '/rpc_fetcher.txt';
2122
require_once __DIR__ . '/ffi.txt';
2223
require_once __DIR__ . '/kml.txt';
2324
require_once __DIR__ . '/pdo/PDO.php';
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace VK\TL;
4+
5+
/** @kphp-required */
6+
interface RpcFunctionFetcher {
7+
public function typedStore($result ::: RpcFunctionReturnResult);
8+
public function typedFetch() : RpcFunctionReturnResult;
9+
}

builtin-functions/kphp-light/stdlib/rpc.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
require_once __DIR__ . '/rpc_fetcher.txt';
4+
35
// ===== SUPPORTED =====
46

57
/** @kphp-tl-class */
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace VK\TL;
4+
5+
/** @kphp-required */
6+
interface RpcFunctionFetcher {
7+
public function typedStore($result ::: RpcFunctionReturnResult);
8+
public function typedFetch() : RpcFunctionReturnResult;
9+
}

common/tl2php/gen-php-code.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,35 @@ size_t gen_rpc_function_classes(const std::string& out_dir, const PhpClasses& cl
629629
<< std::endl
630630
<< make_class(*repr.function_result) << BuiltinClose{*repr.function_args};
631631
}
632+
633+
// we will remove ALL tl2php code soon, so we added a bit hackish code here
634+
const char* content = R"(<?php
635+
636+
/**
637+
* AUTOGENERATED, DO NOT EDIT! If you want to modify it, check tl schema.
638+
*
639+
* This autogenerated code represents tl class for typed RPC API.
640+
*/
641+
642+
#ifndef KPHP
643+
644+
namespace VK\TL;
645+
646+
interface RpcFunctionFetcher {
647+
648+
/**
649+
* @param \VK\TL\RpcFunctionReturnResult $result
650+
*/
651+
public function typedStore($result);
652+
/**
653+
* @return \VK\TL\RpcFunctionReturnResult
654+
*/
655+
public function typedFetch();
656+
}
657+
658+
#endif)";
659+
std::ofstream{out_dir + "/" + PhpClasses::tl_namespace() + "/RpcFunctionFetcher.php"} << content << std::endl;
660+
632661
return classes.functions.size() * 2;
633662
}
634663

runtime-light/stdlib/rpc/rpc-tl-function.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ struct C$VK$TL$RpcFunctionReturnResult : abstract_refcountable_php_interface {
7878
~C$VK$TL$RpcFunctionReturnResult() override = default;
7979
};
8080

81+
// Every TL function has a corresponding Fetcher, which captures nat parameters,
82+
// required to fetch/store function result.
83+
struct C$VK$TL$RpcFunctionFetcher : abstract_refcountable_php_interface {
84+
virtual const char* get_class() const noexcept {
85+
return "VK\\TL\\RpcFunctionFetcher";
86+
}
87+
virtual int32_t get_hash() const noexcept {
88+
std::string_view name_view{C$VK$TL$RpcFunctionFetcher::get_class()};
89+
return static_cast<int32_t>(vk::murmur_hash<uint32_t>(name_view.data(), name_view.size()));
90+
}
91+
92+
virtual void accept(ToArrayVisitor& /*unused*/) noexcept {}
93+
virtual void accept(CommonMemoryEstimateVisitor& /*unused*/) noexcept {}
94+
virtual void accept(InstanceReferencesCountingVisitor& /*unused*/) noexcept {}
95+
virtual void accept(InstanceDeepCopyVisitor& /*unused*/) noexcept {}
96+
virtual void accept(InstanceDeepDestroyVisitor& /*unused*/) noexcept {}
97+
98+
virtual size_t virtual_builtin_sizeof() const noexcept {
99+
return 0;
100+
}
101+
virtual C$VK$TL$RpcFunctionFetcher* virtual_builtin_clone() const noexcept {
102+
return nullptr;
103+
}
104+
105+
~C$VK$TL$RpcFunctionFetcher() override = default;
106+
};
107+
81108
// function call response — ReqResult from the TL scheme — is a rpcResponseOk|rpcResponseHeader|rpcResponseError;
82109
// if it's rpcResponseOk or rpcResponseHeader, then their bodies can be retrieved by a fetcher that was returned by a store
83110
struct C$VK$TL$RpcResponse : abstract_refcountable_php_interface {

runtime/tl/rpc_function.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ struct C$VK$TL$RpcFunctionReturnResult : abstract_refcountable_php_interface {
7878
virtual ~C$VK$TL$RpcFunctionReturnResult() = default;
7979
};
8080

81+
// Every TL function has a corresponding Fetcher, which captures nat parameters,
82+
// required to fetch/store function result.
83+
struct C$VK$TL$RpcFunctionFetcher : abstract_refcountable_php_interface {
84+
virtual const char* get_class() const {
85+
return "VK\\TL\\RpcFunctionFetcher";
86+
}
87+
virtual int32_t get_hash() const {
88+
std::string_view name_view{C$VK$TL$RpcFunctionFetcher::get_class()};
89+
return static_cast<int32_t>(vk::murmur_hash<uint32_t>(name_view.data(), name_view.size()));
90+
}
91+
92+
virtual void accept(ToArrayVisitor&) noexcept {}
93+
virtual void accept(CommonMemoryEstimateVisitor&) noexcept {}
94+
virtual void accept(InstanceReferencesCountingVisitor&) noexcept {}
95+
virtual void accept(InstanceDeepCopyVisitor&) noexcept {}
96+
virtual void accept(InstanceDeepDestroyVisitor&) noexcept {}
97+
98+
virtual size_t virtual_builtin_sizeof() const noexcept {
99+
return 0;
100+
}
101+
virtual C$VK$TL$RpcFunctionFetcher* virtual_builtin_clone() const noexcept {
102+
return nullptr;
103+
}
104+
105+
virtual ~C$VK$TL$RpcFunctionFetcher() = default;
106+
};
107+
81108
// function call response — ReqResult from the TL scheme — is a rpcResponseOk|rpcResponseHeader|rpcResponseError;
82109
// if it's rpcResponseOk or rpcResponseHeader, then their bodies can be retrieved by a fetcher that was returned by a store
83110
struct C$VK$TL$RpcResponse : abstract_refcountable_php_interface {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/**
4+
* AUTOGENERATED, DO NOT EDIT! If you want to modify it, check tl schema.
5+
*
6+
* This autogenerated code represents tl class for typed RPC API.
7+
*/
8+
9+
#ifndef KPHP
10+
11+
namespace VK\TL;
12+
13+
interface RpcFunctionFetcher {
14+
15+
/**
16+
* @param \VK\TL\RpcFunctionReturnResult $result
17+
*/
18+
public function typedStore($result);
19+
/**
20+
* @return \VK\TL\RpcFunctionReturnResult
21+
*/
22+
public function typedFetch();
23+
}
24+
25+
#endif

0 commit comments

Comments
 (0)