forked from google/flatbuffers
/
ReadWriteBuf.java
142 lines (121 loc) · 3.98 KB
/
ReadWriteBuf.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package com.google.flatbuffers;
/**
* Interface to represent a read-write buffer. This interface will be used to access and write
* FlexBuffers message.
*/
public interface ReadWriteBuf extends ReadBuf {
/**
* Clears (resets) the buffer so that it can be reused. Write position will be set to the
* start.
*/
void clear();
/**
* Put a boolean into the buffer at {@code writePosition()} . Booleans as stored as single
* byte. Write position will be incremented.
* @return boolean element
*/
void putBoolean(boolean value);
/**
* Put an array of bytes into the buffer at {@code writePosition()}. Write position will be
* incremented.
* @param value the data to be copied
* @param start initial position on value to be copied
* @param length amount of bytes to be copied
*/
void put (byte[] value, int start, int length);
/**
* Write a byte into the buffer at {@code writePosition()}. Write position will be
* incremented.
*/
void put(byte value);
/**
* Write a 16-bit into in the buffer at {@code writePosition()}. Write position will be
* incremented.
*/
void putShort(short value);
/**
* Write a 32-bit into in the buffer at {@code writePosition()}. Write position will be
* incremented.
*/
void putInt(int value);
/**
* Write a 64-bit into in the buffer at {@code writePosition()}. Write position will be
* incremented.
*/
void putLong(long value);
/**
* Write a 32-bit float into the buffer at {@code writePosition()}. Write position will be
* incremented.
*/
void putFloat(float value);
/**
* Write a 64-bit float into the buffer at {@code writePosition()}. Write position will be
* incremented.
*/
void putDouble(double value);
/**
* Write boolean into a given position on the buffer. Booleans as stored as single byte.
* @param index position of the element in buffer
*/
void setBoolean(int index, boolean value);
/**
* Read a byte from data.
* @param index position of the element in the buffer
* @return a byte
*/
void set(int index, byte value);
/**
* Write an array of bytes into the buffer.
* @param index initial position of the buffer to be written
* @param value the data to be copied
* @param start initial position on value to be copied
* @param length amount of bytes to be copied
*/
void set(int index, byte[] value, int start, int length);
/**
* Read a short from data.
* @param index position of the element in ReadBuf
* @return a short
*/
void setShort(int index, short value);
/**
* Read a 32-bit int from data.
* @param index position of the element in ReadBuf
* @return an int
*/
void setInt(int index, int value);
/**
* Read a 64-bit long from data.
* @param index position of the element in ReadBuf
* @return a long
*/
void setLong(int index, long value);
/**
* Read a 32-bit float from data.
* @param index position of the element in ReadBuf
* @return a float
*/
void setFloat(int index, float value);
/**
* Read a 64-bit float from data.
* @param index position of the element in ReadBuf
* @return a double
*/
void setDouble(int index, double value);
int writePosition();
/**
* Defines the size of the message in the buffer. It also determines last position that buffer
* can be read or write. Last byte to be accessed is in position {@code limit() -1}.
* @return indicate last position
*/
int limit();
/**
* Request capacity of the buffer. In case buffer is already larger
* than the requested, this method will just return true. Otherwise
* It might try to resize the buffer.
*
* @return true if buffer is able to offer
* the requested capacity
*/
boolean requestCapacity(int capacity);
}