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 int getUnsignedMedium(byte[] memory, int index) {
32 return (memory[index] & 0xff) << 16 |
33 (memory[index + 1] & 0xff) << 8 |
34 memory[index + 2] & 0xff;
35 }
36
37 static int getInt(byte[] memory, int index) {
38 return (memory[index] & 0xff) << 24 |
39 (memory[index + 1] & 0xff) << 16 |
40 (memory[index + 2] & 0xff) << 8 |
41 memory[index + 3] & 0xff;
42 }
43
44 static long getLong(byte[] memory, int index) {
45 return ((long) memory[index] & 0xff) << 56 |
46 ((long) memory[index + 1] & 0xff) << 48 |
47 ((long) memory[index + 2] & 0xff) << 40 |
48 ((long) memory[index + 3] & 0xff) << 32 |
49 ((long) memory[index + 4] & 0xff) << 24 |
50 ((long) memory[index + 5] & 0xff) << 16 |
51 ((long) memory[index + 6] & 0xff) << 8 |
52 (long) memory[index + 7] & 0xff;
53 }
54
55 static void setByte(byte[] memory, int index, int value) {
56 memory[index] = (byte) value;
57 }
58
59 static void setShort(byte[] memory, int index, int value) {
60 memory[index] = (byte) (value >>> 8);
61 memory[index + 1] = (byte) value;
62 }
63
64 static void setMedium(byte[] memory, int index, int value) {
65 memory[index] = (byte) (value >>> 16);
66 memory[index + 1] = (byte) (value >>> 8);
67 memory[index + 2] = (byte) value;
68 }
69
70 static void setInt(byte[] memory, int index, int value) {
71 memory[index] = (byte) (value >>> 24);
72 memory[index + 1] = (byte) (value >>> 16);
73 memory[index + 2] = (byte) (value >>> 8);
74 memory[index + 3] = (byte) value;
75 }
76
77 static void setLong(byte[] memory, int index, long value) {
78 memory[index] = (byte) (value >>> 56);
79 memory[index + 1] = (byte) (value >>> 48);
80 memory[index + 2] = (byte) (value >>> 40);
81 memory[index + 3] = (byte) (value >>> 32);
82 memory[index + 4] = (byte) (value >>> 24);
83 memory[index + 5] = (byte) (value >>> 16);
84 memory[index + 6] = (byte) (value >>> 8);
85 memory[index + 7] = (byte) value;
86 }
87
88 private HeapByteBufUtil() { }
89 }