Skip to content

Commit

Permalink
feat: Add MutableRawBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
mrousavy committed Feb 20, 2024
1 parent cfaafa0 commit e14a9cf
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 2 deletions.
38 changes: 38 additions & 0 deletions package/cpp/MutableRawBuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// MutableRawBuffer.cpp
// react-native-filament
//
// Created by Marc Rousavy on 17.01.24.
// Copyright © 2024 mrousavy. All rights reserved.
//

#include "MutableRawBuffer.h"
#include <functional>
#include <memory>

namespace margelo {

MutableRawBuffer::MutableRawBuffer(uint8_t* data, size_t size, bool freeOnDealloc)
: _data(data), _size(size), _freeOnDealloc(freeOnDealloc) {}

MutableRawBuffer::MutableRawBuffer(size_t size) {
_size = size;
_data = (uint8_t*)malloc(size * sizeof(uint8_t));
_freeOnDealloc = true;
}

MutableRawBuffer::~MutableRawBuffer() {
if (_freeOnDealloc) {
free(_data);
}
}

size_t MutableRawBuffer::size() const {
return _size;
}

uint8_t* MutableRawBuffer::data() {
return _data;
}

} // namespace margelo
36 changes: 36 additions & 0 deletions package/cpp/MutableRawBuffer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// MutableRawBuffer.h
// react-native-filament
//
// Created by Marc Rousavy on 17.01.24.
// Copyright © 2024 mrousavy. All rights reserved.
//

#pragma once

#include <functional>
#include <jsi/jsi.h>
#include <memory>

namespace margelo {

using namespace facebook;

class MutableRawBuffer : public jsi::MutableBuffer {

public:
explicit MutableRawBuffer(size_t size);
explicit MutableRawBuffer(uint8_t* data, size_t size, bool freeOnDealloc);
~MutableRawBuffer();

public:
uint8_t* data() override;
size_t size() const override;

private:
uint8_t* _data;
size_t _size;
bool _freeOnDealloc;
};

} // namespace margelo
16 changes: 14 additions & 2 deletions package/react-native-filament.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ Pod::Spec.new do |s|
s.platforms = { :ios => min_ios_version_supported }
s.source = { :git => "https://github.com/margelo/react-native-filament.git", :tag => "#{s.version}" }

s.source_files = "ios/**/*.{h,m,mm}"
# All source files that should be publicly visible
# Note how this does not include headers, since those can nameclash.
s.source_files = [
"ios/**/*.{h,m,mm}",
"cpp/**/*.{h,hpp,c,cpp}"
]
# Any private headers that are not globally unique should be mentioned here.
# Otherwise there will be a nameclash, since CocoaPods flattens out any header directories
# See https://github.com/firebase/firebase-ios-sdk/issues/4035 for more details.
s.preserve_paths = [
"cpp/**/*.h",
"ios/**/*.h"
]

# Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
# See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
Expand All @@ -38,5 +50,5 @@ Pod::Spec.new do |s|
s.dependency "RCTTypeSafety"
s.dependency "ReactCommon/turbomodule/core"
end
end
end
end

0 comments on commit e14a9cf

Please sign in to comment.