2 * Copyright 2015-present Open Networking Foundation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package io.atomix.storage.buffer;
18 import java.nio.charset.Charset;
23 * This interface exposes methods for reading bytes from specific positions in a byte array.
25 * @author <a href="http://github.com/kuujo">Jordan Halterman</a>
27 public interface BytesInput<T extends BytesInput<T>> {
30 * Reads bytes into the given byte array starting at the given offset up to the given length.
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.
38 T read(int offset, Bytes dst, int dstOffset, int length);
41 * Reads bytes into the given byte array starting at the given offset up to the given length.
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.
49 T read(int offset, byte[] dst, int dstOffset, int length);
52 * Reads a byte from the buffer at the given offset.
54 * @param offset The offset at which to read the byte.
55 * @return The read byte.
57 int readByte(int offset);
60 * Reads an unsigned byte from the buffer at the given offset.
62 * @param offset The offset at which to read the byte.
63 * @return The read unsigned byte.
65 int readUnsignedByte(int offset);
68 * Reads a 16-bit character from the buffer at the given offset.
70 * @param offset The offset at which to read the character.
71 * @return The read character.
73 char readChar(int offset);
76 * Reads a 16-bit signed integer from the buffer at the given offset.
78 * @param offset The offset at which to read the short.
79 * @return The read short.
81 short readShort(int offset);
84 * Reads a 16-bit unsigned integer from the buffer at the given offset.
86 * @param offset The offset at which to read the short.
87 * @return The read short.
89 int readUnsignedShort(int offset);
92 * Reads a 24-bit signed integer from the buffer at the given offset.
94 * @param offset The offset at which to read the integer.
95 * @return The read medium.
97 int readMedium(int offset);
100 * Reads a 24-bin unsigned integer from the buffer at the given offset.
102 * @param offset The offset at which to read the integer.
103 * @return The read medium.
105 int readUnsignedMedium(int offset);
108 * Reads a 32-bit signed integer from the buffer at the given offset.
110 * @param offset The offset at which to read the integer.
111 * @return The read integer.
113 int readInt(int offset);
116 * Reads a 32-bit unsigned integer from the buffer at the given offset.
118 * @param offset The offset at which to read the integer.
119 * @return The read integer.
121 long readUnsignedInt(int offset);
124 * Reads a 64-bit signed integer from the buffer at the given offset.
126 * @param offset The offset at which to read the long.
127 * @return The read long.
129 long readLong(int offset);
132 * Reads a single-precision 32-bit floating point number from the buffer at the given offset.
134 * @param offset The offset at which to read the float.
135 * @return The read float.
137 float readFloat(int offset);
140 * Reads a double-precision 64-bit floating point number from the buffer at the given offset.
142 * @param offset The offset at which to read the double.
143 * @return The read double.
145 double readDouble(int offset);
148 * Reads a 1 byte boolean from the buffer at the given offset.
150 * @param offset The offset at which to read the boolean.
151 * @return The read boolean.
153 boolean readBoolean(int offset);
156 * Reads a string from the buffer at the given offset.
158 * @param offset The offset at which to read the string.
159 * @return The read string.
161 String readString(int offset);
164 * Reads a string from the buffer at the given offset.
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.
170 String readString(int offset, Charset charset);
173 * Reads a UTF-8 string from the buffer at the given offset.
175 * @param offset The offset at which to read the string.
176 * @return The read string.
178 String readUTF8(int offset);