Skip to content

Commit 4af1b53

Browse files
author
wangbaiping/wbpcode
committed
simplify the code
Signed-off-by: wangbaiping/wbpcode <[email protected]>
1 parent 260f1b3 commit 4af1b53

File tree

3 files changed

+18
-31
lines changed

3 files changed

+18
-31
lines changed

include/proxy-wasm/null_plugin.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct NullPluginRegistry {
3131
void (*proxy_abi_version_0_1_0_)() = nullptr;
3232
void (*proxy_abi_version_0_2_0_)() = nullptr;
3333
void (*proxy_abi_version_0_2_1_)() = nullptr;
34+
void (*proxy_abi_version_0_3_0_)() = nullptr;
3435
void (*proxy_on_log_)(uint32_t context_id) = nullptr;
3536
uint32_t (*proxy_validate_configuration_)(uint32_t root_context_id,
3637
uint32_t plugin_configuration_size) = nullptr;

src/context.cc

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,13 @@ FilterHeadersStatus ContextBase::onRequestHeaders(uint32_t headers, bool end_of_
322322

323323
AbiVersion wasm_abi_version = wasm_->abi_version_;
324324
uint64_t result{};
325-
switch (wasm_abi_version) {
326-
case AbiVersion::ProxyWasm_0_1_0:
325+
326+
if (wasm_->abi_version_ == AbiVersion::ProxyWasm_0_1_0) {
327+
// For ProxyWasm_0_1_0.
327328
result = wasm_->on_request_headers_abi_01_(this, id_, headers);
328-
break;
329-
case AbiVersion::ProxyWasm_0_2_0:
330-
case AbiVersion::ProxyWasm_0_2_1:
331-
case AbiVersion::ProxyWasm_0_3_0:
329+
} else {
330+
// For ProxyWasm_0_2_0, ProxyWasm_0_2_1, or ProxyWasm_0_3_0.
332331
result = wasm_->on_request_headers_(this, id_, headers, static_cast<uint32_t>(end_of_stream));
333-
break;
334-
case AbiVersion::Unknown:
335-
assert(false); // Should never reach here.
336-
return FilterHeadersStatus::Continue;
337332
}
338333

339334
CHECK_FAIL_HTTP(FilterHeadersStatus::Continue, FilterHeadersStatus::StopAllIterationAndWatermark);
@@ -383,18 +378,13 @@ FilterHeadersStatus ContextBase::onResponseHeaders(uint32_t headers, bool end_of
383378

384379
AbiVersion wasm_abi_version = wasm_->abi_version_;
385380
uint64_t result{};
386-
switch (wasm_abi_version) {
387-
case AbiVersion::ProxyWasm_0_1_0:
381+
382+
if (wasm_->abi_version_ == AbiVersion::ProxyWasm_0_1_0) {
383+
// For ProxyWasm_0_1_0.
388384
result = wasm_->on_response_headers_abi_01_(this, id_, headers);
389-
break;
390-
case AbiVersion::ProxyWasm_0_2_0:
391-
case AbiVersion::ProxyWasm_0_2_1:
392-
case AbiVersion::ProxyWasm_0_3_0:
385+
} else {
386+
// For ProxyWasm_0_2_0, ProxyWasm_0_2_1, or ProxyWasm_0_3_0.
393387
result = wasm_->on_response_headers_(this, id_, headers, static_cast<uint32_t>(end_of_stream));
394-
break;
395-
case AbiVersion::Unknown:
396-
assert(false); // Should never reach here.
397-
return FilterHeadersStatus::Continue;
398388
}
399389

400390
CHECK_FAIL_HTTP(FilterHeadersStatus::Continue, FilterHeadersStatus::StopAllIterationAndWatermark);

src/wasm.cc

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,17 @@ void WasmBase::registerCallbacks() {
140140
FOR_ALL_HOST_FUNCTIONS(_REGISTER_PROXY);
141141

142142
if (abiVersion() == AbiVersion::ProxyWasm_0_1_0) {
143+
// For ProxyWasm_0_1_0.
143144
_REGISTER_PROXY(get_configuration);
144145
_REGISTER_PROXY(continue_request);
145146
_REGISTER_PROXY(continue_response);
146147
_REGISTER_PROXY(clear_route_cache);
147148
} else if (abiVersion() == AbiVersion::ProxyWasm_0_2_0) {
149+
// For ProxyWasm_0_2_0.
148150
_REGISTER_PROXY(continue_stream);
149151
_REGISTER_PROXY(close_stream);
150-
} else if (abiVersion() == AbiVersion::ProxyWasm_0_2_1) {
151-
_REGISTER_PROXY(continue_stream);
152-
_REGISTER_PROXY(close_stream);
153-
_REGISTER_PROXY(get_log_level);
154-
} else if (abiVersion() == AbiVersion::ProxyWasm_0_3_0) {
152+
} else {
153+
// For ProxyWasm_0_2_1 or ProxyWasm_0_3_0.
155154
_REGISTER_PROXY(continue_stream);
156155
_REGISTER_PROXY(close_stream);
157156
_REGISTER_PROXY(get_log_level);
@@ -198,14 +197,11 @@ void WasmBase::getFunctions() {
198197
FOR_ALL_MODULE_FUNCTIONS(_GET_PROXY);
199198

200199
if (abiVersion() == AbiVersion::ProxyWasm_0_1_0) {
200+
// For ProxyWasm_0_1_0.
201201
_GET_PROXY_ABI(on_request_headers, _abi_01);
202202
_GET_PROXY_ABI(on_response_headers, _abi_01);
203-
} else if (abiVersion() == AbiVersion::ProxyWasm_0_2_0 ||
204-
abiVersion() == AbiVersion::ProxyWasm_0_2_1) {
205-
_GET_PROXY(on_request_headers);
206-
_GET_PROXY(on_response_headers);
207-
_GET_PROXY(on_foreign_function);
208-
} else if (abiVersion() == AbiVersion::ProxyWasm_0_3_0) {
203+
} else {
204+
// For ProxyWasm_0_2_0, ProxyWasm_0_2_1, or ProxyWasm_0_3_0.
209205
_GET_PROXY(on_request_headers);
210206
_GET_PROXY(on_response_headers);
211207
_GET_PROXY(on_foreign_function);

0 commit comments

Comments
 (0)