FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
lmdbjava/src/main/java/org/lmdbjava/BufferProxy.java at gh-267 · lmdbjava/lmdbjava · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
lmdbjava
/
lmdbjava
Public
Notifications
You must be signed in to change notification settings
Fork
126
Star
873
Code
Issues
8
Pull requests
6
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
lmdbjava
/
src
/
main
/
java
/
org
/
lmdbjava
/
BufferProxy.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
141 lines (123 loc) · 4.78 KB
Breadcrumbs
lmdbjava
/
src
/
main
/
java
/
org
/
lmdbjava
/
BufferProxy.java
Copy path
File metadata and controls
141 lines (123 loc) · 4.78 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
/*
* Copyright © 2016-2025 The LmdbJava Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
lmdbjava
;
import
static
java
.
lang
.
Long
.
BYTES
;
import
static
org
.
lmdbjava
.
DbiFlags
.
MDB_INTEGERKEY
;
import
static
org
.
lmdbjava
.
DbiFlags
.
MDB_UNSIGNEDKEY
;
import
static
org
.
lmdbjava
.
MaskedFlag
.
isSet
;
import
static
org
.
lmdbjava
.
MaskedFlag
.
mask
;
import
java
.
util
.
Comparator
;
import
jnr
.
ffi
.
Pointer
;
/**
* The strategy for mapping memory address to a given buffer type.
*
* <p>The proxy is passed to the {@link Env#create(org.lmdbjava.BufferProxy)} method and is
* subsequently used by every {@link Txn}, {@link Dbi} and {@link Cursor} associated with the {@link
* Env}.
*
* @param <T> buffer type
*/
public
abstract
class
BufferProxy
<
T
> {
/** Size of a <code>MDB_val</code> pointer in bytes. */
protected
static
final
int
MDB_VAL_STRUCT_SIZE
=
BYTES
*
2
;
/** Offset from a pointer of the <code>MDB_val.mv_data</code> field. */
protected
static
final
int
STRUCT_FIELD_OFFSET_DATA
=
BYTES
;
/** Offset from a pointer of the <code>MDB_val.mv_size</code> field. */
protected
static
final
int
STRUCT_FIELD_OFFSET_SIZE
=
0
;
/** Explicitly-defined default constructor to avoid warnings. */
protected
BufferProxy
() {}
/**
* Allocate a new buffer suitable for passing to {@link #out(java.lang.Object, jnr.ffi.Pointer)}.
*
* @return a buffer for passing to the <code>out</code> method
*/
protected
abstract
T
allocate
();
/**
* Deallocate a buffer that was previously provided by {@link #allocate()}.
*
* @param buff the buffer to deallocate (required)
*/
protected
abstract
void
deallocate
(
T
buff
);
/**
* Obtain a copy of the bytes contained within the passed buffer.
*
* @param buffer a non-null buffer created by this proxy instance
* @return a copy of the bytes this buffer is currently representing
*/
protected
abstract
byte
[]
getBytes
(
T
buffer
);
/**
* Get a suitable default {@link Comparator} given the provided flags.
*
* <p>The provided comparator must strictly match the lexicographical order of keys in the native
* LMDB database.
*
* @param flags for the database
* @return a comparator that can be used (never null)
*/
protected
Comparator
<
T
>
getComparator
(
DbiFlags
...
flags
) {
final
int
intFlag
=
mask
(
flags
);
return
isSet
(
intFlag
,
MDB_INTEGERKEY
) ||
isSet
(
intFlag
,
MDB_UNSIGNEDKEY
)
?
getUnsignedComparator
()
:
getSignedComparator
();
}
/**
* Get a suitable default {@link Comparator} to compare numeric key values as signed.
*
* @return a comparator that can be used (never null)
*/
protected
abstract
Comparator
<
T
>
getSignedComparator
();
/**
* Get a suitable default {@link Comparator} to compare numeric key values as unsigned.
*
* @return a comparator that can be used (never null)
*/
protected
abstract
Comparator
<
T
>
getUnsignedComparator
();
/**
* Called when the <code>MDB_val</code> should be set to reflect the passed buffer. This buffer
* will have been created by end users, not {@link #allocate()}.
*
* @param buffer the buffer to write to <code>MDB_val</code>
* @param ptr the pointer to the <code>MDB_val</code>
* @return a transient pointer that must be kept alive, or null if none
*/
protected
abstract
Pointer
in
(
T
buffer
,
Pointer
ptr
);
/**
* Called when the <code>MDB_val</code> should be set to reflect the passed buffer.
*
* @param buffer the buffer to write to <code>MDB_val</code>
* @param size the buffer size to write to <code>MDB_val</code>
* @param ptr the pointer to the <code>MDB_val</code>
* @return a transient pointer that must be kept alive, or null if none
*/
protected
abstract
Pointer
in
(
T
buffer
,
int
size
,
Pointer
ptr
);
/**
* Called when the <code>MDB_val</code> may have changed and the passed buffer should be modified
* to reflect the new <code>MDB_val</code>.
*
* @param buffer the buffer to write to <code>MDB_val</code>
* @param ptr the pointer to the <code>MDB_val</code>
* @return the buffer for <code>MDB_val</code>
*/
protected
abstract
T
out
(
T
buffer
,
Pointer
ptr
);
/**
* Create a new {@link KeyVal} to hold pointers for this buffer proxy.
*
* @return a non-null key value holder
*/
final
KeyVal
<
T
>
keyVal
() {
return
new
KeyVal
<>(
this
);
}
}
Back
|
FazBrowse Home
|
New Git URL