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