Import atomix/{storage,utils}
[controller.git] / third-party / atomix / storage / src / main / java / io / atomix / storage / buffer / BytesInput.java
1 /*
2  * Copyright 2015-present Open Networking Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * 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,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package io.atomix.storage.buffer;
17
18 import java.nio.charset.Charset;
19
20 /**
21  * Readable bytes.
22  * <p>
23  * This interface exposes methods for reading bytes from specific positions in a byte array.
24  *
25  * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
26  */
27 public interface BytesInput<T extends BytesInput<T>> {
28
29   /**
30    * Reads bytes into the given byte array starting at the given offset up to the given length.
31    *
32    * @param offset    The offset from which to start reading bytes.
33    * @param dst       The byte array into which to read bytes.
34    * @param dstOffset The offset at which to write bytes into the given buffer.
35    * @param length    The total number of bytes to read.
36    * @return The buffer.
37    */
38   T read(int offset, Bytes dst, int dstOffset, int length);
39
40   /**
41    * Reads bytes into the given byte array starting at the given offset up to the given length.
42    *
43    * @param offset    The offset from which to start reading bytes.
44    * @param dst       The byte array into which to read bytes.
45    * @param dstOffset The offset at which to write bytes into the given buffer
46    * @param length    The total number of bytes to read.
47    * @return The buffer.
48    */
49   T read(int offset, byte[] dst, int dstOffset, int length);
50
51   /**
52    * Reads a byte from the buffer at the given offset.
53    *
54    * @param offset The offset at which to read the byte.
55    * @return The read byte.
56    */
57   int readByte(int offset);
58
59   /**
60    * Reads an unsigned byte from the buffer at the given offset.
61    *
62    * @param offset The offset at which to read the byte.
63    * @return The read unsigned byte.
64    */
65   int readUnsignedByte(int offset);
66
67   /**
68    * Reads a 16-bit character from the buffer at the given offset.
69    *
70    * @param offset The offset at which to read the character.
71    * @return The read character.
72    */
73   char readChar(int offset);
74
75   /**
76    * Reads a 16-bit signed integer from the buffer at the given offset.
77    *
78    * @param offset The offset at which to read the short.
79    * @return The read short.
80    */
81   short readShort(int offset);
82
83   /**
84    * Reads a 16-bit unsigned integer from the buffer at the given offset.
85    *
86    * @param offset The offset at which to read the short.
87    * @return The read short.
88    */
89   int readUnsignedShort(int offset);
90
91   /**
92    * Reads a 24-bit signed integer from the buffer at the given offset.
93    *
94    * @param offset The offset at which to read the integer.
95    * @return The read medium.
96    */
97   int readMedium(int offset);
98
99   /**
100    * Reads a 24-bin unsigned integer from the buffer at the given offset.
101    *
102    * @param offset The offset at which to read the integer.
103    * @return The read medium.
104    */
105   int readUnsignedMedium(int offset);
106
107   /**
108    * Reads a 32-bit signed integer from the buffer at the given offset.
109    *
110    * @param offset The offset at which to read the integer.
111    * @return The read integer.
112    */
113   int readInt(int offset);
114
115   /**
116    * Reads a 32-bit unsigned integer from the buffer at the given offset.
117    *
118    * @param offset The offset at which to read the integer.
119    * @return The read integer.
120    */
121   long readUnsignedInt(int offset);
122
123   /**
124    * Reads a 64-bit signed integer from the buffer at the given offset.
125    *
126    * @param offset The offset at which to read the long.
127    * @return The read long.
128    */
129   long readLong(int offset);
130
131   /**
132    * Reads a single-precision 32-bit floating point number from the buffer at the given offset.
133    *
134    * @param offset The offset at which to read the float.
135    * @return The read float.
136    */
137   float readFloat(int offset);
138
139   /**
140    * Reads a double-precision 64-bit floating point number from the buffer at the given offset.
141    *
142    * @param offset The offset at which to read the double.
143    * @return The read double.
144    */
145   double readDouble(int offset);
146
147   /**
148    * Reads a 1 byte boolean from the buffer at the given offset.
149    *
150    * @param offset The offset at which to read the boolean.
151    * @return The read boolean.
152    */
153   boolean readBoolean(int offset);
154
155   /**
156    * Reads a string from the buffer at the given offset.
157    *
158    * @param offset The offset at which to read the string.
159    * @return The read string.
160    */
161   String readString(int offset);
162
163   /**
164    * Reads a string from the buffer at the given offset.
165    *
166    * @param offset  The offset at which to read the string.
167    * @param charset The character set with which to decode the string.
168    * @return The read string.
169    */
170   String readString(int offset, Charset charset);
171
172   /**
173    * Reads a UTF-8 string from the buffer at the given offset.
174    *
175    * @param offset The offset at which to read the string.
176    * @return The read string.
177    */
178   String readUTF8(int offset);
179
180 }