Rename C++ part of ReadableMapBuffer to JReadableMapBuffer

Summary:
Aligns naming with `JWritableMapBuffer` and other fbjni classes to indicate that it is a JNI binding.

Changelog: [Internal] - Rename C++ part of ReadableMapBuffer to JReadableMapBuffer

Reviewed By: mdvacca

Differential Revision: D35219323

fbshipit-source-id: a7eb644a700a35dc94fa18e4fb3cc68f2cfa3e99
This commit is contained in:
Andrei Shikov
2022-03-30 20:27:23 -07:00
committed by Facebook GitHub Bot
parent 81e4249315
commit 2a6a6851ec
11 changed files with 71 additions and 80 deletions
@@ -0,0 +1,43 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "JReadableMapBuffer.h"
namespace facebook {
namespace react {
void JReadableMapBuffer::registerNatives() {
registerHybrid({
makeNativeMethod(
"importByteBuffer", JReadableMapBuffer::importByteBuffer),
});
}
jni::local_ref<jni::JByteBuffer> JReadableMapBuffer::importByteBuffer() {
// TODO T83483191: Reevaluate what's the best approach here (allocateDirect vs
// DirectByteBuffer).
return jni::JByteBuffer::wrapBytes(
serializedData_.data(), serializedData_.size());
}
std::vector<uint8_t> JReadableMapBuffer::data() const {
return serializedData_;
}
jni::local_ref<JReadableMapBuffer::jhybridobject>
JReadableMapBuffer::createWithContents(MapBuffer &&map) {
return newObjectCxxArgs(std::move(map));
}
JReadableMapBuffer::JReadableMapBuffer(MapBuffer &&map)
: serializedData_(std::move(map.bytes_)) {
react_native_assert(
(serializedData_.size() != 0) && "Error no content in map");
}
} // namespace react
} // namespace facebook
@@ -16,17 +16,17 @@
namespace facebook {
namespace react {
class ReadableMapBuffer : public jni::HybridClass<ReadableMapBuffer> {
class JReadableMapBuffer : public jni::HybridClass<JReadableMapBuffer> {
public:
static auto constexpr kJavaDescriptor =
"Lcom/facebook/react/common/mapbuffer/ReadableMapBuffer;";
static void registerNatives();
static jni::local_ref<ReadableMapBuffer::jhybridobject> createWithContents(
static jni::local_ref<JReadableMapBuffer::jhybridobject> createWithContents(
MapBuffer &&map);
explicit ReadableMapBuffer(MapBuffer &&map);
explicit JReadableMapBuffer(MapBuffer &&map);
jni::local_ref<jni::JByteBuffer> importByteBuffer();
@@ -33,7 +33,7 @@ MapBuffer JWritableMapBuffer::getMapBuffer() {
static const auto integerClass = jni::JInteger::javaClassStatic();
static const auto doubleClass = jni::JDouble::javaClassStatic();
static const auto stringClass = jni::JString::javaClassStatic();
static const auto readableMapClass = ReadableMapBuffer::javaClassStatic();
static const auto readableMapClass = JReadableMapBuffer::javaClassStatic();
static const auto writableMapClass = JWritableMapBuffer::javaClassStatic();
if (value->isInstanceOf(booleanClass)) {
@@ -50,7 +50,7 @@ MapBuffer JWritableMapBuffer::getMapBuffer() {
builder.putString(key, element->toStdString());
} else if (value->isInstanceOf(readableMapClass)) {
auto element =
jni::static_ref_cast<ReadableMapBuffer::jhybridobject>(value);
jni::static_ref_cast<JReadableMapBuffer::jhybridobject>(value);
builder.putMapBuffer(key, MapBuffer(element->cthis()->data()));
} else if (value->isInstanceOf(writableMapClass)) {
auto element =
@@ -8,7 +8,7 @@
#pragma once
#include <fbjni/fbjni.h>
#include <react/common/mapbuffer/ReadableMapBuffer.h>
#include <react/common/mapbuffer/JReadableMapBuffer.h>
namespace facebook::react {
@@ -7,10 +7,10 @@
#include <fbjni/fbjni.h>
#include "JReadableMapBuffer.h"
#include "JWritableMapBuffer.h"
#include "ReadableMapBuffer.h"
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) {
return facebook::jni::initialize(
vm, [] { facebook::react::ReadableMapBuffer::registerNatives(); });
vm, [] { facebook::react::JReadableMapBuffer::registerNatives(); });
}
@@ -1,52 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ReadableMapBuffer.h"
namespace facebook {
namespace react {
void ReadableMapBuffer::registerNatives() {
registerHybrid({
makeNativeMethod("importByteBuffer", ReadableMapBuffer::importByteBuffer),
});
}
jni::local_ref<jni::JByteBuffer> ReadableMapBuffer::importByteBuffer() {
// TODO T83483191: Reevaluate what's the best approach here (allocateDirect vs
// DirectByteBuffer).
//
// On this method we should:
// - Review deallocation of serializedData (we are probably leaking
// _serializedData now).
// - Consider using allocate() or allocateDirect() methods from java instead
// of newDirectByteBuffer (to simplify de/allocation) :
// https://www.internalfb.com/intern/diffusion/FBS/browsefile/master/fbandroid/libraries/fbjni/cxx/fbjni/ByteBuffer.cpp
// - Add flags to describe if the data was already 'imported'
// - Long-term: Consider creating a big ByteBuffer that can be re-used to
// transfer data of multitple Maps
return jni::JByteBuffer::wrapBytes(
serializedData_.data(), serializedData_.size());
}
std::vector<uint8_t> ReadableMapBuffer::data() const {
return serializedData_;
}
jni::local_ref<ReadableMapBuffer::jhybridobject>
ReadableMapBuffer::createWithContents(MapBuffer &&map) {
return newObjectCxxArgs(std::move(map));
}
ReadableMapBuffer::ReadableMapBuffer(MapBuffer &&map)
: serializedData_(std::move(map.bytes_)) {
react_native_assert(
(serializedData_.size() != 0) && "Error no content in map");
}
} // namespace react
} // namespace facebook
@@ -255,7 +255,7 @@ local_ref<jobject> FabricMountingManager::getProps(
? static_cast<ViewProps const &>(*oldShadowView.props)
: ViewProps{};
auto newProps = static_cast<ViewProps const &>(*newShadowView.props);
return ReadableMapBuffer::createWithContents(
return JReadableMapBuffer::createWithContents(
viewPropsDiff(oldProps, newProps));
} else {
return ReadableNativeMap::newObjectCxxArgs(newShadowView.props->rawProps);
@@ -32,12 +32,12 @@ StateWrapperImpl::getStateDataImpl() {
return readableNativeMap;
}
jni::local_ref<ReadableMapBuffer::jhybridobject>
jni::local_ref<JReadableMapBuffer::jhybridobject>
StateWrapperImpl::getStateMapBufferDataImpl() {
MapBuffer map = state_->getMapBuffer();
auto ReadableMapBuffer =
ReadableMapBuffer::createWithContents(std::move(map));
return ReadableMapBuffer;
auto readableMapBuffer =
JReadableMapBuffer::createWithContents(std::move(map));
return readableMapBuffer;
}
void StateWrapperImpl::updateStateImpl(NativeMap *map) {
@@ -8,7 +8,7 @@
#pragma once
#include <fbjni/fbjni.h>
#include <react/common/mapbuffer/ReadableMapBuffer.h>
#include <react/common/mapbuffer/JReadableMapBuffer.h>
#include <react/jni/ReadableNativeMap.h>
#include <react/renderer/core/State.h>
@@ -26,7 +26,7 @@ class StateWrapperImpl : public jni::HybridClass<StateWrapperImpl> {
static void registerNatives();
jni::local_ref<ReadableMapBuffer::jhybridobject> getStateMapBufferDataImpl();
jni::local_ref<JReadableMapBuffer::jhybridobject> getStateMapBufferDataImpl();
jni::local_ref<ReadableNativeMap::jhybridobject> getStateDataImpl();
void updateStateImpl(NativeMap *map);