查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2013 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License,
5    * version 2.0 (the "License"); you may not use this file except in compliance
6    * with the License. You may obtain a copy of the License at:
7    *
8    *   https://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13   * License for the specific language governing permissions and limitations
14   * under the License.
15   */
16  package io.netty.handler.codec.memcache.binary;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.Unpooled;
20  import io.netty.util.internal.UnstableApi;
21  
22  /**
23   * The decoder which takes care of decoding the response headers.
24   */
25  @UnstableApi
26  public class BinaryMemcacheResponseDecoder
27      extends AbstractBinaryMemcacheDecoder<BinaryMemcacheResponse> {
28  
29      public BinaryMemcacheResponseDecoder() {
30          this(DEFAULT_MAX_CHUNK_SIZE);
31      }
32  
33      public BinaryMemcacheResponseDecoder(int chunkSize) {
34          super(chunkSize);
35      }
36  
37      @Override
38      protected BinaryMemcacheResponse decodeHeader(ByteBuf in) {
39          DefaultBinaryMemcacheResponse header = new DefaultBinaryMemcacheResponse();
40          header.setMagic(in.readByte());
41          header.setOpcode(in.readByte());
42          header.setKeyLength(in.readShort());
43          header.setExtrasLength(in.readByte());
44          header.setDataType(in.readByte());
45          header.setStatus(in.readShort());
46          header.setTotalBodyLength(in.readInt());
47          header.setOpaque(in.readInt());
48          header.setCas(in.readLong());
49          return header;
50      }
51  
52      @Override
53      protected BinaryMemcacheResponse buildInvalidMessage() {
54          return new DefaultBinaryMemcacheResponse(Unpooled.EMPTY_BUFFER, Unpooled.EMPTY_BUFFER);
55      }
56  }