1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.buffer;
17
18
19
20
21 final class HeapByteBufUtil {
22
23 static byte getByte(byte[] memory, int index) {
24 return memory[index];
25 }
26
27 static short getShort(byte[] memory, int index) {
28 return (short) (memory[index] << 8 | memory[index + 1] & 0xFF);
29 }
30
31 static short getShortLE(byte[] memory, int index) {
32 return (short) (memory[index] & 0xff | memory[index + 1] << 8);
33 }
34
35 static int getUnsignedMedium(byte[] memory, int index) {
36 return (memory[index] & 0xff) << 16 |
37 (memory[index + 1] & 0xff) << 8 |
38 memory[index + 2] & 0xff;
39 }
40
41 static int getUnsignedMediumLE(byte[] memory, int index) {
42 return memory[index] & 0xff |
43 (memory[index + 1] & 0xff) << 8 |
44 (memory[index + 2] & 0xff) << 16;
45 }
46
47 static int getInt(byte[] memory, int index) {
48 return (memory[index] & 0xff) << 24 |
49 (memory[index + 1] & 0xff) << 16 |
50 (memory[index + 2] & 0xff) << 8 |
51 memory[index + 3] & 0xff;
52 }
53
54 static int getIntLE(byte[] memory, int index) {
55 return memory[index] & 0xff |
56 (memory[index + 1] & 0xff) << 8 |
57 (memory[index + 2] & 0xff) << 16 |
58 (memory[index + 3] & 0xff) << 24;
59 }
60
61 static long getLong(byte[] memory, int index) {
62 return ((long) memory[index] & 0xff) << 56 |
63 ((long) memory[index + 1] & 0xff) << 48 |
64 ((long) memory[index + 2] & 0xff) << 40 |
65 ((long) memory[index + 3] & 0xff) << 32 |
66 ((long) memory[index + 4] & 0xff) << 24 |
67 ((long) memory[index + 5] & 0xff) << 16 |
68 ((long) memory[index + 6] & 0xff) << 8 |
69 (long) memory[index + 7] & 0xff;
70 }
71
72 static long getLongLE(byte[] memory, int index) {
73 return (long) memory[index] & 0xff |
74 ((long) memory[index + 1] & 0xff) << 8 |
75 ((long) memory[index + 2] & 0xff) << 16 |
76 ((long) memory[index + 3] & 0xff) << 24 |
77 ((long) memory[index + 4] & 0xff) << 32 |
78 ((long) memory[index + 5] & 0xff) << 40 |
79 ((long) memory[index + 6] & 0xff) << 48 |
80 ((long) memory[index + 7] & 0xff) << 56;
81 }
82
83 static void setByte(byte[] memory, int index, int value) {
84 memory[index] = (byte) value;
85 }
86
87 static void setShort(byte[] memory, int index, int value) {
88 memory[index] = (byte) (value >>> 8);
89 memory[index + 1] = (byte) value;
90 }
91
92 static void setShortLE(byte[] memory, int index, int value) {
93 memory[index] = (byte) value;
94 memory[index + 1] = (byte) (value >>> 8);
95 }
96
97 static void setMedium(byte[] memory, int index, int value) {
98 memory[index] = (byte) (value >>> 16);
99 memory[index + 1] = (byte) (value >>> 8);
100 memory[index + 2] = (byte) value;
101 }
102
103 static void setMediumLE(byte[] memory, int index, int value) {
104 memory[index] = (byte) value;
105 memory[index + 1] = (byte) (value >>> 8);
106 memory[index + 2] = (byte) (value >>> 16);
107 }
108
109 static void setInt(byte[] memory, int index, int value) {
110 memory[index] = (byte) (value >>> 24);
111 memory[index + 1] = (byte) (value >>> 16);
112 memory[index + 2] = (byte) (value >>> 8);
113 memory[index + 3] = (byte) value;
114 }
115
116 static void setIntLE(byte[] memory, int index, int value) {
117 memory[index] = (byte) value;
118 memory[index + 1] = (byte) (value >>> 8);
119 memory[index + 2] = (byte) (value >>> 16);
120 memory[index + 3] = (byte) (value >>> 24);
121 }
122
123 static void setLong(byte[] memory, int index, long value) {
124 memory[index] = (byte) (value >>> 56);
125 memory[index + 1] = (byte) (value >>> 48);
126 memory[index + 2] = (byte) (value >>> 40);
127 memory[index + 3] = (byte) (value >>> 32);
128 memory[index + 4] = (byte) (value >>> 24);
129 memory[index + 5] = (byte) (value >>> 16);
130 memory[index + 6] = (byte) (value >>> 8);
131 memory[index + 7] = (byte) value;
132 }
133
134 static void setLongLE(byte[] memory, int index, long value) {
135 memory[index] = (byte) value;
136 memory[index + 1] = (byte) (value >>> 8);
137 memory[index + 2] = (byte) (value >>> 16);
138 memory[index + 3] = (byte) (value >>> 24);
139 memory[index + 4] = (byte) (value >>> 32);
140 memory[index + 5] = (byte) (value >>> 40);
141 memory[index + 6] = (byte) (value >>> 48);
142 memory[index + 7] = (byte) (value >>> 56);
143 }
144
145 private HeapByteBufUtil() { }
146 }