1 /*
2 * Copyright 2015 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.UnpooledSlicedByteBuf;
17
18 import hunt.net.buffer.AbstractByteBuf;
19 import hunt.net.buffer.AbstractUnpooledSlicedByteBuf;
20 import hunt.net.buffer.ByteBuf;
21 import hunt.net.buffer.ByteBufAllocator;
22 import hunt.net.buffer.ByteBufUtil;
23 import hunt.net.buffer.ByteProcessor;
24
25 import hunt.Byte;
26 import hunt.io.ByteBuffer;
27 import hunt.Exceptions;
28 import hunt.net.Exceptions;
29 import hunt.stream.Common;
30 import hunt.util.StringBuilder;
31
32 import std.conv;
33 import std.format;
34
35 /**
36 * A special {@link AbstractUnpooledSlicedByteBuf} that can make optimizations because it knows the sliced buffer is of
37 * type {@link AbstractByteBuf}.
38 */
39 class UnpooledSlicedByteBuf : AbstractUnpooledSlicedByteBuf {
40 this(AbstractByteBuf buffer, int index, int length) {
41 super(buffer, index, length);
42 }
43
44 override
45 int capacity() {
46 return maxCapacity();
47 }
48
49 override
50 AbstractByteBuf unwrap() {
51 return cast(AbstractByteBuf) super.unwrap();
52 }
53
54 override
55 protected byte _getByte(int index) {
56 return unwrap()._getByte(idx(index));
57 }
58
59 override
60 protected short _getShort(int index) {
61 return unwrap()._getShort(idx(index));
62 }
63
64 override
65 protected short _getShortLE(int index) {
66 return unwrap()._getShortLE(idx(index));
67 }
68
69 override
70 protected int _getUnsignedMedium(int index) {
71 return unwrap()._getUnsignedMedium(idx(index));
72 }
73
74 override
75 protected int _getUnsignedMediumLE(int index) {
76 return unwrap()._getUnsignedMediumLE(idx(index));
77 }
78
79 override
80 protected int _getInt(int index) {
81 return unwrap()._getInt(idx(index));
82 }
83
84 override
85 protected int _getIntLE(int index) {
86 return unwrap()._getIntLE(idx(index));
87 }
88
89 override
90 protected long _getLong(int index) {
91 return unwrap()._getLong(idx(index));
92 }
93
94 override
95 protected long _getLongLE(int index) {
96 return unwrap()._getLongLE(idx(index));
97 }
98
99 override
100 protected void _setByte(int index, int value) {
101 unwrap()._setByte(idx(index), value);
102 }
103
104 override
105 protected void _setShort(int index, int value) {
106 unwrap()._setShort(idx(index), value);
107 }
108
109 override
110 protected void _setShortLE(int index, int value) {
111 unwrap()._setShortLE(idx(index), value);
112 }
113
114 override
115 protected void _setMedium(int index, int value) {
116 unwrap()._setMedium(idx(index), value);
117 }
118
119 override
120 protected void _setMediumLE(int index, int value) {
121 unwrap()._setMediumLE(idx(index), value);
122 }
123
124 override
125 protected void _setInt(int index, int value) {
126 unwrap()._setInt(idx(index), value);
127 }
128
129 override
130 protected void _setIntLE(int index, int value) {
131 unwrap()._setIntLE(idx(index), value);
132 }
133
134 override
135 protected void _setLong(int index, long value) {
136 unwrap()._setLong(idx(index), value);
137 }
138
139 override
140 protected void _setLongLE(int index, long value) {
141 unwrap()._setLongLE(idx(index), value);
142 }
143 }