Add `JByteBuffer::rewind()`
Summary: Adds a `rewind()` method to `JByteBuffer`, which maps to `java.nio.Buffer#rewind()`. This is useful if a `ByteBuffer` is reused for calls between Java and C++. Differential Revision: D7435171 fbshipit-source-id: 488131d6ad2d5abb1b86a5efabc2f39ba0ab16cd
This commit is contained in:
parent
e88f128608
commit
ff2260b022
|
@ -15,6 +15,13 @@
|
|||
namespace facebook {
|
||||
namespace jni {
|
||||
|
||||
class JBuffer : public JavaClass<JBuffer> {
|
||||
public:
|
||||
static constexpr const char* kJavaDescriptor = "Ljava/nio/Buffer;";
|
||||
|
||||
void rewind() const;
|
||||
};
|
||||
|
||||
// JNI's NIO support has some awkward preconditions and error reporting. This
|
||||
// class provides much more user-friendly access.
|
||||
class FBEXPORT JByteBuffer : public JavaClass<JByteBuffer> {
|
||||
|
|
|
@ -22,6 +22,11 @@ local_ref<JByteBuffer> createEmpty() {
|
|||
}
|
||||
}
|
||||
|
||||
void JBuffer::rewind() const {
|
||||
static auto meth = javaClassStatic()->getMethod<alias_ref<JBuffer>()>("rewind");
|
||||
meth(self());
|
||||
}
|
||||
|
||||
local_ref<JByteBuffer> JByteBuffer::wrapBytes(uint8_t* data, size_t size) {
|
||||
// env->NewDirectByteBuffer requires that size is positive. Android's
|
||||
// dalvik returns an invalid result and Android's art aborts if size == 0.
|
||||
|
|
Loading…
Reference in New Issue