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