2323
2424import lombok .RequiredArgsConstructor ;
2525import lombok .experimental .FieldDefaults ;
26+ import lombok .val ;
2627
2728/**
2829 *
@@ -35,6 +36,30 @@ final class BytesDelegateGets {
3536
3637 Bytes bytes ;
3738
39+ /**
40+ * Returns unsigned byte as short integer (2 bytes).
41+ *
42+ * @return unsigned byte
43+ *
44+ * @since 1.3.1
45+ */
46+ public short getUnsignedByte () {
47+ return BytesUtils .asUnsignedByte (bytes .getByte ());
48+ }
49+
50+ /**
51+ * Returns unsigned byte as short integer (2 bytes) from specific position.
52+ *
53+ * @param index index in buffer, where extract unsigned byte.
54+ *
55+ * @return unsigned byte
56+ *
57+ * @since 1.3.1
58+ */
59+ public short getUnsignedByte (int index ) {
60+ return BytesUtils .asUnsignedByte (bytes .getByte (index ));
61+ }
62+
3863 public char getChar () {
3964 return bytes .getBuffer ().getChar ();
4065 }
@@ -55,14 +80,59 @@ public short getShort (int index) {
5580 return bytes .getBuffer ().getShort (index );
5681 }
5782
83+ /**
84+ * Returns unsigned short (2 bytes) as integer (4 bytes) from specific position.
85+ *
86+ * @param index index in buffer, where extract unsigned short.
87+ *
88+ * @return unsigned short
89+ *
90+ * @since 1.3.1
91+ */
92+ public int getUnsignedShort (int index ) {
93+ return getShort (index ) & 0xFFFF ;
94+ }
95+
5896 public int getInt () {
5997 return bytes .getBuffer ().getInt ();
6098 }
6199
100+ /**
101+ * Returns unsigned integer (4 bytes) as long (8 bytes).
102+ *
103+ * @return unsigned integer
104+ *
105+ * @since 1.3.1
106+ */
107+ public long getUnsignedInt () {
108+ val intBytes = bytes .getBytes (Integer .BYTES );
109+ return BytesUtils .asUnsignedInteger (intBytes );
110+ }
111+
62112 public int getInt (int index ) {
63113 return bytes .getBuffer ().getInt (index );
64114 }
65115
116+ /**
117+ * Returns unsigned integer (4 bytes) as long (8 bytes) from specific position.
118+ *
119+ * @param index index in buffer, where extract unsigned intger.
120+ *
121+ * @return unsigned integer
122+ *
123+ * @since 1.3.1
124+ */
125+ public long getUnsignedInt (int index ) {
126+ val oldPosition = bytes .position ();
127+ try {
128+ bytes .position (index );
129+ val intBytes = bytes .getBytes (Integer .BYTES );
130+ return BytesUtils .asUnsignedInteger (intBytes );
131+ } finally {
132+ bytes .position (oldPosition );
133+ }
134+ }
135+
66136 public long getLong () {
67137 return bytes .getBuffer ().getLong ();
68138 }
0 commit comments