-
Notifications
You must be signed in to change notification settings - Fork 56
/
OakScopedWriteBuffer.java
129 lines (118 loc) · 5.55 KB
/
OakScopedWriteBuffer.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
/*
* Copyright 2020, Verizon Media.
* Licensed under the terms of the Apache 2.0 license.
* Please see LICENSE file in the project root for terms.
*/
package com.yahoo.oak;
/**
* This buffer may represent either a key or a value for read/write access.
* It mimic the standard interface of Java's ByteBuffer, for example, int getInt(int index), char getChar(int index),
* capacity(), etc.
* <p>
* It is attached to the scope of the callback method it were first introduced to the user.
* The behaviour of this buffer outside their attached scope is undefined.
* Such callback method might be the application's serializer and comparator, or a lambda function that can
* read/store/update the data.
* This access reduces unnecessary copies and deserialization of the underlying data.
* In their intended context, the user does not need to worry about concurrent accesses and memory management.
* Using these buffers outside their intended context may yield unpredicted results, e.g., reading non-consistent data
* and/or irrelevant data.
*/
public interface OakScopedWriteBuffer extends OakBuffer {
/**
* Absolute <i>put</i> method <i>(optional operation)</i>.
* <p> Writes the given byte into this buffer at the given
* index. </p>
*
* @param index The index at which the byte will be written
* @param b The byte value to be written
* @return This buffer
* @throws IndexOutOfBoundsException If <tt>index</tt> is negative
* or not smaller than the buffer's limit
*/
OakScopedWriteBuffer put(int index, byte b);
/**
* Absolute <i>put</i> method for writing a char
* value <i>(optional operation)</i>.
* <p> Writes two bytes containing the given char value, in the
* current byte order, into this buffer at the given index. </p>
*
* @param index The index at which the bytes will be written
* @param value The char value to be written
* @return This buffer
* @throws IndexOutOfBoundsException If <tt>index</tt> is negative
* or not smaller than the buffer's limit,
* minus one
*/
OakScopedWriteBuffer putChar(int index, char value);
/**
* Absolute <i>put</i> method for writing a short
* value <i>(optional operation)</i>.
* <p> Writes two bytes containing the given short value, in the
* current byte order, into this buffer at the given index. </p>
*
* @param index The index at which the bytes will be written
* @param value The short value to be written
* @return This buffer
* @throws IndexOutOfBoundsException If <tt>index</tt> is negative
* or not smaller than the buffer's limit,
* minus one
*/
OakScopedWriteBuffer putShort(int index, short value);
/**
* Absolute <i>put</i> method for writing an int
* value <i>(optional operation)</i>.
* <p> Writes four bytes containing the given int value, in the
* current byte order, into this buffer at the given index. </p>
*
* @param index The index at which the bytes will be written
* @param value The int value to be written
* @return This buffer
* @throws IndexOutOfBoundsException If <tt>index</tt> is negative
* or not smaller than the buffer's limit,
* minus three
*/
OakScopedWriteBuffer putInt(int index, int value);
/**
* Absolute <i>put</i> method for writing a long
* value <i>(optional operation)</i>.
* <p> Writes eight bytes containing the given long value, in the
* current byte order, into this buffer at the given index. </p>
*
* @param index The index at which the bytes will be written
* @param value The long value to be written
* @return This buffer
* @throws IndexOutOfBoundsException If <tt>index</tt> is negative
* or not smaller than the buffer's limit,
* minus seven
*/
OakScopedWriteBuffer putLong(int index, long value);
/**
* Absolute <i>put</i> method for writing a float
* value <i>(optional operation)</i>.
* <p> Writes four bytes containing the given float value, in the
* current byte order, into this buffer at the given index. </p>
*
* @param index The index at which the bytes will be written
* @param value The float value to be written
* @return This buffer
* @throws IndexOutOfBoundsException If <tt>index</tt> is negative
* or not smaller than the buffer's limit,
* minus three
*/
OakScopedWriteBuffer putFloat(int index, float value);
/**
* Absolute <i>put</i> method for writing a double
* value <i>(optional operation)</i>.
* <p> Writes eight bytes containing the given double value, in the
* current byte order, into this buffer at the given index. </p>
*
* @param index The index at which the bytes will be written
* @param value The double value to be written
* @return This buffer
* @throws IndexOutOfBoundsException If <tt>index</tt> is negative
* or not smaller than the buffer's limit,
* minus seven
*/
OakScopedWriteBuffer putDouble(int index, double value);
}