public A6Request decode()

in runner-core/src/main/java/org/apache/apisix/plugin/runner/handler/PayloadDecoder.java [48:105]


    public A6Request decode(ByteBuffer buffer) {
        byte type;
        try {
            type = buffer.get();
        } catch (BufferUnderflowException e) {
            logger.warn("receive empty data");
            return new A6ErrRequest(Code.BAD_REQUEST);
        }

        ByteBuffer body;
        switch (type) {
            case Constants.RPC_PREPARE_CONF:
                A6ConfigRequest a6ConfigRequest;
                try {
                    body = getBody(buffer);
                    a6ConfigRequest = A6ConfigRequest.from(body);
                } catch (BufferUnderflowException | IndexOutOfBoundsException e) {
                    logger.warn("receive error data length");
                    return new A6ErrRequest(Code.BAD_REQUEST);
                }
                return a6ConfigRequest;
            case Constants.RPC_HTTP_REQ_CALL:
                HttpRequest httpRequest;
                try {
                    body = getBody(buffer);
                    httpRequest = HttpRequest.from(body);
                } catch (BufferUnderflowException | IndexOutOfBoundsException e) {
                    return new A6ErrRequest(Code.BAD_REQUEST);
                }
                return httpRequest;

            case Constants.RPC_EXTRA_INFO:
                ExtraInfoResponse extraInfoResponse;
                try {
                    body = getBody(buffer);
                    extraInfoResponse = ExtraInfoResponse.from(body);
                } catch (BufferUnderflowException | IndexOutOfBoundsException e) {
                    return new A6ErrRequest(Code.BAD_REQUEST);
                }
                return extraInfoResponse;

            case Constants.RPC_HTTP_RESP_CALL:
                PostRequest postRequest;
                try {
                    body = getBody(buffer);
                    postRequest = PostRequest.from(body);
                } catch (BufferUnderflowException | IndexOutOfBoundsException e) {
                    return new A6ErrRequest(Code.BAD_REQUEST);
                }
                return postRequest;

            default:
                break;
        }

        logger.warn("receive unsupported type: {}", type);
        return new A6ErrRequest(Code.BAD_REQUEST);
    }