Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add bigEndian() and littleEndian() fields to JByteOrder #93

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cxx/fbjni/ByteBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,18 @@ local_ref<JByteOrder> JByteOrder::nativeOrder() {
return meth(JByteOrder::javaClassStatic());
}

local_ref<JByteOrder> JByteOrder::bigEndian() {
static auto field =
JByteOrder::javaClassStatic()->getStaticField<JByteOrder>("BIG_ENDIAN");
return JByteOrder::javaClassStatic()->getStaticFieldValue(field);
}

local_ref<JByteOrder> JByteOrder::littleEndian() {
static auto field =
JByteOrder::javaClassStatic()->getStaticField<JByteOrder>("LITTLE_ENDIAN");
return JByteOrder::javaClassStatic()->getStaticFieldValue(field);
}

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.
Expand Down
2 changes: 2 additions & 0 deletions cxx/fbjni/ByteBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class JByteOrder : public JavaClass<JByteOrder> {
constexpr static const char* kJavaDescriptor = "Ljava/nio/ByteOrder;";

static local_ref<JByteOrder> nativeOrder();
static local_ref<JByteOrder> bigEndian();
static local_ref<JByteOrder> littleEndian();
};

// JNI's NIO support has some awkward preconditions and error reporting. This
Expand Down
Loading