Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
feat: streamlined code, solid codecs (#4)
- Loading branch information
1 parent
62c2e2c
commit 17a690375652a545026a8ae4d2c474b99438d3a1
Showing
22 changed files
with
400 additions
and
472 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.apisix.plugin.runner.codec.impl; | ||
|
||
import io.github.api7.A6.Err.Code; | ||
import org.apache.apisix.plugin.runner.A6ConfigRequest; | ||
import org.apache.apisix.plugin.runner.A6ErrRequest; | ||
import org.apache.apisix.plugin.runner.A6Request; | ||
import org.apache.apisix.plugin.runner.HttpRequest; | ||
import org.apache.apisix.plugin.runner.codec.PluginRunnerDecoder; | ||
import org.apache.apisix.plugin.runner.codec.frame.FrameCodec; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class FlatBuffersDecoder implements PluginRunnerDecoder { | ||
|
||
private final Logger logger = LoggerFactory.getLogger(FlatBuffersDecoder.class); | ||
|
||
@Override | ||
public A6Request decode(ByteBuffer buffer) { | ||
byte type = buffer.get(); | ||
ByteBuffer body = FrameCodec.getBody(buffer); | ||
switch (type) { | ||
case 1: | ||
return A6ConfigRequest.from(body); | ||
case 2: | ||
return HttpRequest.from(body); | ||
default: | ||
break; | ||
} | ||
|
||
logger.error("receive unsupported type: {}", type); | ||
return new A6ErrRequest(Code.BAD_REQUEST); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.apisix.plugin.runner.codec.impl; | ||
|
||
import org.apache.apisix.plugin.runner.A6Response; | ||
import org.apache.apisix.plugin.runner.codec.PluginRunnerEncoder; | ||
import org.apache.apisix.plugin.runner.codec.frame.FrameCodec; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class FlatBuffersEncoder implements PluginRunnerEncoder { | ||
|
||
@Override | ||
public ByteBuffer encode(A6Response response) { | ||
ByteBuffer buffer = response.encode(); | ||
if (null != response.getErrResponse()) { | ||
return FrameCodec.setBody(buffer, (byte) 0); | ||
} | ||
return FrameCodec.setBody(buffer, response.getType()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.