查看本类的 API文档回源码主页即时通讯网 - 即时通讯开发者社区!
1   /*
2    * Copyright 2016 The Netty Project
3    *
4    * The Netty Project licenses this file to you under the Apache License, version 2.0 (the
5    * "License"); you may not use this file except in compliance with the License. You may obtain a
6    * 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 distributed under the License
11   * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing permissions and limitations under
13   * the License.
14   */
15  
16  package io.netty.handler.codec.redis;
17  
18  import io.netty.buffer.ByteBuf;
19  import io.netty.buffer.DefaultByteBufHolder;
20  import io.netty.buffer.Unpooled;
21  import io.netty.util.internal.StringUtil;
22  import io.netty.util.internal.UnstableApi;
23  
24  /**
25   * An aggregated bulk string of <a href="https://redis.io/topics/protocol">RESP</a>.
26   */
27  @UnstableApi
28  public class FullBulkStringRedisMessage extends DefaultByteBufHolder implements LastBulkStringRedisContent {
29  
30      private FullBulkStringRedisMessage() {
31          this(Unpooled.EMPTY_BUFFER);
32      }
33  
34      /**
35       * Creates a {@link FullBulkStringRedisMessage} for the given {@code content}.
36       *
37       * @param content the content, must not be {@code null}. If content is null or empty,
38       * use {@link FullBulkStringRedisMessage#NULL_INSTANCE} or {@link FullBulkStringRedisMessage#EMPTY_INSTANCE}
39       * instead of constructor.
40       */
41      public FullBulkStringRedisMessage(ByteBuf content) {
42          super(content);
43      }
44  
45      /**
46       * Returns whether the content of this message is {@code null}.
47       *
48       * @return indicates whether the content of this message is {@code null}.
49       */
50      public boolean isNull() {
51          return false;
52      }
53  
54      @Override
55      public String toString() {
56          return new StringBuilder(StringUtil.simpleClassName(this))
57                  .append('[')
58                  .append("content=")
59                  .append(content())
60                  .append(']').toString();
61      }
62  
63      /**
64       * A predefined null instance of {@link FullBulkStringRedisMessage}.
65       */
66      public static final FullBulkStringRedisMessage NULL_INSTANCE = new FullBulkStringRedisMessage() {
67          @Override
68          public boolean isNull() {
69              return true;
70          }
71  
72          @Override
73          public ByteBuf content() {
74              return Unpooled.EMPTY_BUFFER;
75          }
76  
77          @Override
78          public FullBulkStringRedisMessage copy() {
79              return this;
80          }
81  
82          @Override
83          public FullBulkStringRedisMessage duplicate() {
84              return this;
85          }
86  
87          @Override
88          public FullBulkStringRedisMessage retainedDuplicate() {
89              return this;
90          }
91  
92          @Override
93          public int refCnt() {
94              return 1;
95          }
96  
97          @Override
98          public FullBulkStringRedisMessage retain() {
99              return this;
100         }
101 
102         @Override
103         public FullBulkStringRedisMessage retain(int increment) {
104             return this;
105         }
106 
107         @Override
108         public FullBulkStringRedisMessage touch() {
109             return this;
110         }
111 
112         @Override
113         public FullBulkStringRedisMessage touch(Object hint) {
114             return this;
115         }
116 
117         @Override
118         public boolean release() {
119             return false;
120         }
121 
122         @Override
123         public boolean release(int decrement) {
124             return false;
125         }
126     };
127 
128     /**
129      * A predefined empty instance of {@link FullBulkStringRedisMessage}.
130      */
131     public static final FullBulkStringRedisMessage EMPTY_INSTANCE = new FullBulkStringRedisMessage() {
132         @Override
133         public ByteBuf content() {
134             return Unpooled.EMPTY_BUFFER;
135         }
136 
137         @Override
138         public FullBulkStringRedisMessage copy() {
139             return this;
140         }
141 
142         @Override
143         public FullBulkStringRedisMessage duplicate() {
144             return this;
145         }
146 
147         @Override
148         public FullBulkStringRedisMessage retainedDuplicate() {
149             return this;
150         }
151 
152         @Override
153         public int refCnt() {
154             return 1;
155         }
156 
157         @Override
158         public FullBulkStringRedisMessage retain() {
159             return this;
160         }
161 
162         @Override
163         public FullBulkStringRedisMessage retain(int increment) {
164             return this;
165         }
166 
167         @Override
168         public FullBulkStringRedisMessage touch() {
169             return this;
170         }
171 
172         @Override
173         public FullBulkStringRedisMessage touch(Object hint) {
174             return this;
175         }
176 
177         @Override
178         public boolean release() {
179             return false;
180         }
181 
182         @Override
183         public boolean release(int decrement) {
184             return false;
185         }
186     };
187 
188     @Override
189     public FullBulkStringRedisMessage copy() {
190         return (FullBulkStringRedisMessage) super.copy();
191     }
192 
193     @Override
194     public FullBulkStringRedisMessage duplicate() {
195         return (FullBulkStringRedisMessage) super.duplicate();
196     }
197 
198     @Override
199     public FullBulkStringRedisMessage retainedDuplicate() {
200         return (FullBulkStringRedisMessage) super.retainedDuplicate();
201     }
202 
203     @Override
204     public FullBulkStringRedisMessage replace(ByteBuf content) {
205         return new FullBulkStringRedisMessage(content);
206     }
207 
208     @Override
209     public FullBulkStringRedisMessage retain() {
210         super.retain();
211         return this;
212     }
213 
214     @Override
215     public FullBulkStringRedisMessage retain(int increment) {
216         super.retain(increment);
217         return this;
218     }
219 
220     @Override
221     public FullBulkStringRedisMessage touch() {
222         super.touch();
223         return this;
224     }
225 
226     @Override
227     public FullBulkStringRedisMessage touch(Object hint) {
228         super.touch(hint);
229         return this;
230     }
231 }