View Javadoc
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.util.internal.UnstableApi;
20  
21  /**
22   * The default implementation of the {@link BinaryMemcacheRequest}.
23   */
24  @UnstableApi
25  public class DefaultBinaryMemcacheRequest extends AbstractBinaryMemcacheMessage implements BinaryMemcacheRequest {
26  
27      /**
28       * Default magic byte for a request.
29       */
30      public static final byte REQUEST_MAGIC_BYTE = (byte) 0x80;
31  
32      private short reserved;
33  
34      /**
35       * Create a new {@link DefaultBinaryMemcacheRequest} with the header only.
36       */
37      public DefaultBinaryMemcacheRequest() {
38          this(null, null);
39      }
40  
41      /**
42       * Create a new {@link DefaultBinaryMemcacheRequest} with the header and key.
43       *
44       * @param key    the key to use.
45       */
46      public DefaultBinaryMemcacheRequest(ByteBuf key) {
47          this(key, null);
48      }
49  
50      /**
51       * Create a new {@link DefaultBinaryMemcacheRequest} with the header only.
52       *
53       * @param key    the key to use.
54       * @param extras the extras to use.
55       */
56      public DefaultBinaryMemcacheRequest(ByteBuf key, ByteBuf extras) {
57          super(key, extras);
58          setMagic(REQUEST_MAGIC_BYTE);
59      }
60  
61      @Override
62      public short reserved() {
63          return reserved;
64      }
65  
66      @Override
67      public BinaryMemcacheRequest setReserved(short reserved) {
68          this.reserved = reserved;
69          return this;
70      }
71  
72      @Override
73      public BinaryMemcacheRequest retain() {
74          super.retain();
75          return this;
76      }
77  
78      @Override
79      public BinaryMemcacheRequest retain(int increment) {
80          super.retain(increment);
81          return this;
82      }
83  
84      @Override
85      public BinaryMemcacheRequest touch() {
86          super.touch();
87          return this;
88      }
89  
90      @Override
91      public BinaryMemcacheRequest touch(Object hint) {
92          super.touch(hint);
93          return this;
94      }
95  
96      /**
97       * Copies special metadata hold by this instance to the provided instance
98       *
99       * @param dst The instance where to copy the metadata of this instance to
100      */
101     void copyMeta(DefaultBinaryMemcacheRequest dst) {
102         super.copyMeta(dst);
103         dst.reserved = reserved;
104     }
105 }