View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.db.protocol.codec;
19  
20  import io.netty.buffer.ByteBuf;
21  import io.netty.channel.ChannelHandlerContext;
22  import org.apache.shardingsphere.db.protocol.packet.DatabasePacket;
23  import org.apache.shardingsphere.db.protocol.payload.PacketPayload;
24  
25  import java.nio.charset.Charset;
26  import java.util.List;
27  
28  /**
29   * Database packet codec engine.
30   */
31  public interface DatabasePacketCodecEngine {
32      
33      /**
34       * Judge is valid header or not.
35       * 
36       * @param readableBytes readable bytes
37       * @return is valid header or not
38       */
39      boolean isValidHeader(int readableBytes);
40      
41      /**
42       * Decode.
43       *
44       * @param context channel handler context
45       * @param in input
46       * @param out output
47       */
48      void decode(ChannelHandlerContext context, ByteBuf in, List<Object> out);
49      
50      /**
51       * Encode.
52       * 
53       * @param context channel handler context
54       * @param message message of database packet
55       * @param out output
56       */
57      void encode(ChannelHandlerContext context, DatabasePacket message, ByteBuf out);
58      
59      /**
60       * Create packet payload.
61       *
62       * @param message message
63       * @param charset charset
64       * @return packet payload
65       */
66      PacketPayload createPacketPayload(ByteBuf message, Charset charset);
67  }