1 /* 2 * Copyright 2012 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 * http://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 module hunt.net.buffer.DuplicatedByteBuf; 17 18 import hunt.net.buffer.AbstractDerivedByteBuf; 19 import hunt.net.buffer.AbstractByteBuf; 20 import hunt.net.buffer.ByteBuf; 21 import hunt.net.buffer.ByteBufAllocator; 22 import hunt.net.buffer.ByteProcessor; 23 24 import hunt.Byte; 25 import hunt.io.ByteBuffer; 26 import hunt.stream.Common; 27 import hunt.util.ByteOrder; 28 29 /** 30 * A derived buffer which simply forwards all data access requests to its 31 * parent. It is recommended to use {@link ByteBuf#duplicate()} instead 32 * of calling the constructor explicitly. 33 * 34 * deprecated("") Do not use. 35 */ 36 class DuplicatedByteBuf : AbstractDerivedByteBuf { 37 38 private ByteBuf buffer; 39 40 this(ByteBuf buffer) { 41 this(buffer, buffer.readerIndex(), buffer.writerIndex()); 42 } 43 44 this(ByteBuf buffer, int readerIndex, int writerIndex) { 45 super(buffer.maxCapacity()); 46 DuplicatedByteBuf b = cast(DuplicatedByteBuf)buffer; 47 // AbstractPooledDerivedByteBuf a = cast(AbstractPooledDerivedByteBuf)buffer; 48 49 if (b !is null) { 50 this.buffer = b.buffer; 51 // } else if (a !is null) { 52 // this.buffer = buffer.unwrap(); 53 } else { 54 this.buffer = buffer; 55 } 56 57 setIndex(readerIndex, writerIndex); 58 markReaderIndex(); 59 markWriterIndex(); 60 } 61 62 override 63 ByteBuf unwrap() { 64 return buffer; 65 } 66 67 override 68 ByteBufAllocator alloc() { 69 return unwrap().alloc(); 70 } 71 72 override 73 // deprecated("") 74 ByteOrder order() { 75 return unwrap().order(); 76 } 77 78 override 79 bool isDirect() { 80 return unwrap().isDirect(); 81 } 82 83 override 84 int capacity() { 85 return unwrap().capacity(); 86 } 87 88 override 89 ByteBuf capacity(int newCapacity) { 90 unwrap().capacity(newCapacity); 91 return this; 92 } 93 94 override 95 bool hasArray() { 96 return unwrap().hasArray(); 97 } 98 99 override 100 byte[] array() { 101 return unwrap().array(); 102 } 103 104 override 105 int arrayOffset() { 106 return unwrap().arrayOffset(); 107 } 108 109 override 110 bool hasMemoryAddress() { 111 return unwrap().hasMemoryAddress(); 112 } 113 114 override 115 long memoryAddress() { 116 return unwrap().memoryAddress(); 117 } 118 119 override 120 byte getByte(int index) { 121 return unwrap().getByte(index); 122 } 123 124 override 125 protected byte _getByte(int index) { 126 return unwrap().getByte(index); 127 } 128 129 override 130 short getShort(int index) { 131 return unwrap().getShort(index); 132 } 133 134 override 135 protected short _getShort(int index) { 136 return unwrap().getShort(index); 137 } 138 139 override 140 short getShortLE(int index) { 141 return unwrap().getShortLE(index); 142 } 143 144 override 145 protected short _getShortLE(int index) { 146 return unwrap().getShortLE(index); 147 } 148 149 override 150 int getUnsignedMedium(int index) { 151 return unwrap().getUnsignedMedium(index); 152 } 153 154 override 155 protected int _getUnsignedMedium(int index) { 156 return unwrap().getUnsignedMedium(index); 157 } 158 159 override 160 int getUnsignedMediumLE(int index) { 161 return unwrap().getUnsignedMediumLE(index); 162 } 163 164 override 165 protected int _getUnsignedMediumLE(int index) { 166 return unwrap().getUnsignedMediumLE(index); 167 } 168 169 override 170 int getInt(int index) { 171 return unwrap().getInt(index); 172 } 173 174 override 175 protected int _getInt(int index) { 176 return unwrap().getInt(index); 177 } 178 179 override 180 int getIntLE(int index) { 181 return unwrap().getIntLE(index); 182 } 183 184 override 185 protected int _getIntLE(int index) { 186 return unwrap().getIntLE(index); 187 } 188 189 override 190 long getLong(int index) { 191 return unwrap().getLong(index); 192 } 193 194 override 195 protected long _getLong(int index) { 196 return unwrap().getLong(index); 197 } 198 199 override 200 long getLongLE(int index) { 201 return unwrap().getLongLE(index); 202 } 203 204 override 205 protected long _getLongLE(int index) { 206 return unwrap().getLongLE(index); 207 } 208 209 override 210 ByteBuf copy(int index, int length) { 211 return unwrap().copy(index, length); 212 } 213 214 override 215 ByteBuf slice(int index, int length) { 216 return unwrap().slice(index, length); 217 } 218 219 override 220 ByteBuf getBytes(int index, ByteBuf dst, int dstIndex, int length) { 221 unwrap().getBytes(index, dst, dstIndex, length); 222 return this; 223 } 224 225 override 226 ByteBuf getBytes(int index, byte[] dst, int dstIndex, int length) { 227 unwrap().getBytes(index, dst, dstIndex, length); 228 return this; 229 } 230 231 override 232 ByteBuf getBytes(int index, ByteBuffer dst) { 233 unwrap().getBytes(index, dst); 234 return this; 235 } 236 237 override 238 ByteBuf setByte(int index, int value) { 239 unwrap().setByte(index, value); 240 return this; 241 } 242 243 override 244 protected void _setByte(int index, int value) { 245 unwrap().setByte(index, value); 246 } 247 248 override 249 ByteBuf setShort(int index, int value) { 250 unwrap().setShort(index, value); 251 return this; 252 } 253 254 override 255 protected void _setShort(int index, int value) { 256 unwrap().setShort(index, value); 257 } 258 259 override 260 ByteBuf setShortLE(int index, int value) { 261 unwrap().setShortLE(index, value); 262 return this; 263 } 264 265 override 266 protected void _setShortLE(int index, int value) { 267 unwrap().setShortLE(index, value); 268 } 269 270 override 271 ByteBuf setMedium(int index, int value) { 272 unwrap().setMedium(index, value); 273 return this; 274 } 275 276 override 277 protected void _setMedium(int index, int value) { 278 unwrap().setMedium(index, value); 279 } 280 281 override 282 ByteBuf setMediumLE(int index, int value) { 283 unwrap().setMediumLE(index, value); 284 return this; 285 } 286 287 override 288 protected void _setMediumLE(int index, int value) { 289 unwrap().setMediumLE(index, value); 290 } 291 292 override 293 ByteBuf setInt(int index, int value) { 294 unwrap().setInt(index, value); 295 return this; 296 } 297 298 override 299 protected void _setInt(int index, int value) { 300 unwrap().setInt(index, value); 301 } 302 303 override 304 ByteBuf setIntLE(int index, int value) { 305 unwrap().setIntLE(index, value); 306 return this; 307 } 308 309 override 310 protected void _setIntLE(int index, int value) { 311 unwrap().setIntLE(index, value); 312 } 313 314 override 315 ByteBuf setLong(int index, long value) { 316 unwrap().setLong(index, value); 317 return this; 318 } 319 320 override 321 protected void _setLong(int index, long value) { 322 unwrap().setLong(index, value); 323 } 324 325 override 326 ByteBuf setLongLE(int index, long value) { 327 unwrap().setLongLE(index, value); 328 return this; 329 } 330 331 override 332 protected void _setLongLE(int index, long value) { 333 unwrap().setLongLE(index, value); 334 } 335 336 override 337 ByteBuf setBytes(int index, byte[] src, int srcIndex, int length) { 338 unwrap().setBytes(index, src, srcIndex, length); 339 return this; 340 } 341 342 override 343 ByteBuf setBytes(int index, ByteBuf src, int srcIndex, int length) { 344 unwrap().setBytes(index, src, srcIndex, length); 345 return this; 346 } 347 348 override 349 ByteBuf setBytes(int index, ByteBuffer src) { 350 unwrap().setBytes(index, src); 351 return this; 352 } 353 354 override 355 ByteBuf getBytes(int index, OutputStream outStream, int length) { 356 unwrap().getBytes(index, outStream, length); 357 return this; 358 } 359 360 // override 361 // int getBytes(int index, GatheringByteChannel outStream, int length) { 362 // return unwrap().getBytes(index, outStream, length); 363 // } 364 365 // override 366 // int getBytes(int index, FileChannel outStream, long position, int length) { 367 // return unwrap().getBytes(index, outStream, position, length); 368 // } 369 370 override 371 int setBytes(int index, InputStream inStream, int length) { 372 return unwrap().setBytes(index, inStream, length); 373 } 374 375 // override 376 // int setBytes(int index, ScatteringByteChannel inStream, int length) { 377 // return unwrap().setBytes(index, inStream, length); 378 // } 379 380 // override 381 // int setBytes(int index, FileChannel inStream, long position, int length) { 382 // return unwrap().setBytes(index, inStream, position, length); 383 // } 384 385 override 386 int nioBufferCount() { 387 return unwrap().nioBufferCount(); 388 } 389 390 override 391 ByteBuffer[] nioBuffers(int index, int length) { 392 return unwrap().nioBuffers(index, length); 393 } 394 395 override 396 int forEachByte(int index, int length, ByteProcessor processor) { 397 return unwrap().forEachByte(index, length, processor); 398 } 399 400 override 401 int forEachByteDesc(int index, int length, ByteProcessor processor) { 402 return unwrap().forEachByteDesc(index, length, processor); 403 } 404 } 405