blob: 751361fa25bb75f320006f750934784f29457240 [file] [log] [blame]
Austin Schuh272c6132020-11-14 16:37:52 -08001package com.google.flatbuffers;
2
3/**
4 * Represent a chunk of data, where FlexBuffers will read from.
5 */
6public interface ReadBuf {
7
8 /**
9 * Read boolean from data. Booleans as stored as single byte
10 * @param index position of the element in ReadBuf
11 * @return boolean element
12 */
13 boolean getBoolean(int index);
14
15 /**
16 * Read a byte from data.
17 * @param index position of the element in ReadBuf
18 * @return a byte
19 */
20 byte get(int index);
21
22 /**
23 * Read a short from data.
24 * @param index position of the element in ReadBuf
25 * @return a short
26 */
27 short getShort(int index);
28
29 /**
30 * Read a 32-bit int from data.
31 * @param index position of the element in ReadBuf
32 * @return an int
33 */
34 int getInt(int index);
35
36 /**
37 * Read a 64-bit long from data.
38 * @param index position of the element in ReadBuf
39 * @return a long
40 */
41 long getLong(int index);
42
43 /**
44 * Read a 32-bit float from data.
45 * @param index position of the element in ReadBuf
46 * @return a float
47 */
48 float getFloat(int index);
49
50 /**
51 * Read a 64-bit float from data.
52 * @param index position of the element in ReadBuf
53 * @return a double
54 */
55 double getDouble(int index);
56
57 /**
58 * Read an UTF-8 string from data.
59 * @param start initial element of the string
60 * @param size size of the string in bytes.
61 * @return a {@code String}
62 */
63 String getString(int start, int size);
64
65 /**
66 * Expose ReadBuf as an array of bytes.
67 * This method is meant to be as efficient as possible, so for a array-backed ReadBuf, it should
68 * return its own internal data. In case access to internal data is not possible,
69 * a copy of the data into an array of bytes might occur.
70 * @return ReadBuf as an array of bytes
71 */
72 byte[] data();
73
74 /**
75 * Defines the size of the message in the buffer. It also determines last position that buffer
76 * can be read. Last byte to be accessed is in position {@code limit() -1}.
77 * @return indicate last position
78 */
79 int limit();
80
81}