Skip to content

Commit b867d58

Browse files
authored
remove dep on Buffer (#25980)
1 parent 6bf3891 commit b867d58

43 files changed

Lines changed: 406 additions & 442 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

protocol/bin/flow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ ${project.import.map(n => importMap[n] || '').join('\n')}
477477
${project.import.map(n => `export {${n}}`).join('\n')}
478478
export type Bool = boolean
479479
export type Boolean = boolean
480-
export type Bytes = Buffer
480+
export type Bytes = Uint8Array
481481
export type Double = number
482482
export type Int = number
483483
export type Int64 = number

rnmodules/react-native-kb/android/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ message(INFO "params: ${NODE_MODULES_DIR}")
1616
# Specifies a path to native header files.
1717
include_directories(
1818
../cpp
19-
"${NODE_MODULES_DIR}/msgpack-cxx-4.1.1/include"
19+
"${NODE_MODULES_DIR}/msgpack-cxx-6.1.0/include"
2020
)
2121

2222
set_target_properties(

rnmodules/react-native-kb/cpp/react-native-kb.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,21 +78,19 @@ Value convertMPToJSI(Runtime &runtime, msgpack::object &o) {
7878
case msgpack::type::BIN: {
7979
auto ptr = o.via.bin.ptr;
8080
int size = o.via.bin.size;
81-
// make ArrayBuffer and copy in data
82-
Function arrayBufferCtor =
83-
runtime.global().getPropertyAsFunction(runtime, "ArrayBuffer");
84-
Value ab = arrayBufferCtor.callAsConstructor(runtime, size);
85-
Object abo = ab.getObject(runtime);
86-
ArrayBuffer abbuf = abo.getArrayBuffer(runtime);
87-
std::copy(ptr, ptr + size, abbuf.data(runtime));
88-
89-
// Wrap in Buffer like framed-msg-pack
90-
Object bufObj = runtime.global().getPropertyAsObject(runtime, "Buffer");
91-
Function bufFrom = bufObj.getPropertyAsFunction(runtime, "from");
92-
Value buf = bufFrom.callWithThis(
93-
runtime, bufObj,
94-
std::move(ab)); // Buffer shares the memory and just wraps
95-
return buf;
81+
82+
// make ArrayBuffer and copy in data
83+
Function arrayBufferCtor =
84+
runtime.global().getPropertyAsFunction(runtime, "ArrayBuffer");
85+
Value ab = arrayBufferCtor.callAsConstructor(runtime, size);
86+
Object abo = ab.getObject(runtime);
87+
ArrayBuffer abbuf = abo.getArrayBuffer(runtime);
88+
std::copy(ptr, ptr + size, abbuf.data(runtime));
89+
90+
// Wrap in Uint8Array
91+
Function uCtor = runtime.global().getPropertyAsFunction(runtime, "Uint8Array");
92+
Value uc = uCtor.callAsConstructor(runtime, std::move(abbuf));
93+
return uc;
9694
}
9795
case msgpack::type::ARRAY: {
9896
auto size = o.via.array.size;

rnmodules/react-native-kb/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-kb",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "misc kb",
55
"main": "lib/commonjs/index",
66
"module": "lib/module/index",

rnmodules/react-native-kb/react-native-kb.podspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Pod::Spec.new do |s|
2626
if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
2727
s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
2828
s.pod_target_xcconfig = {
29-
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" $(PODS_ROOT)/../../node_modules/msgpack-cxx-4.1.1/include $(PODS_ROOT)/../keybase.xcframework/ios-arm64/Keybase.framework/Headers",
29+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" $(PODS_ROOT)/../../node_modules/msgpack-cxx-6.1.0/include $(PODS_ROOT)/../keybase.xcframework/ios-arm64/Keybase.framework/Headers",
3030
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DMSGPACK_NO_BOOST=1",
3131
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
3232
}
@@ -37,7 +37,7 @@ Pod::Spec.new do |s|
3737
s.dependency "ReactCommon/turbomodule/core"
3838
else
3939
s.pod_target_xcconfig = {
40-
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" $(PODS_ROOT)/../../node_modules/msgpack-cxx-4.1.1/include $(PODS_ROOT)/../keybase.xcframework/ios-arm64/Keybase.framework/Headers",
40+
"HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\" $(PODS_ROOT)/../../node_modules/msgpack-cxx-6.1.0/include $(PODS_ROOT)/../keybase.xcframework/ios-arm64/Keybase.framework/Headers",
4141
"OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DMSGPACK_NO_BOOST=1",
4242
"CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
4343
}

shared/app/globals.native.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22
// >>>>>>>>>>>>>>>>>>>>>>> DO NOT REORDER ANYTHING in this file <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
33
// This is supposed to bootstrap / polyfill / fixup the app. Do NOT add things here or change things unless you really know
44
// what's happening
5-
//
6-
// Needed for purepack
7-
// @ts-ignore
8-
globalThis.buffer = global.Buffer = window.Buffer = require('buffer/').Buffer
5+
import 'fastestsmallesttextencoderdecoder'
96
__FILE_SUFFIX__ = ''
107
__PROFILE__ = false
118
__HOT__ = false

shared/chat/conversation/fwd-msg/team-picker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const TeamPicker = (props: Props) => {
2020
const message = C.useChatContext(s => s.messageMap.get(ordinal))
2121
const [pickerState, setPickerState] = React.useState<PickerState>('picker')
2222
const [term, setTerm] = React.useState('')
23-
const dstConvIDRef = React.useRef<Buffer | undefined>()
23+
const dstConvIDRef = React.useRef<Uint8Array | undefined>()
2424
const [results, setResults] = React.useState<Array<T.RPCChat.ConvSearchHit>>([])
2525
const [waiting, setWaiting] = React.useState(false)
2626
const [error, setError] = React.useState('')

shared/chat/conversation/normal/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export type Props = {
66
requestScrollToBottomRef: React.MutableRefObject<undefined | (() => void)>
77
requestScrollUpRef: React.MutableRefObject<undefined | (() => void)>
88
requestScrollDownRef: React.MutableRefObject<undefined | (() => void)>
9-
onPaste: (data: Buffer) => void
9+
onPaste: (data: Uint8Array) => void
1010
onAttach?: (paths: Array<string>) => void
1111
onFocusInput: () => void
1212
onRequestScrollDown: () => void

shared/common-adapters/markdown/service-decoration.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
renderEmoji as renderEmojiType,
1616
RPCToEmojiData as RPCToEmojiDataType,
1717
} from '../../util/emoji'
18+
import {base64ToUint8Array, uint8ArrayToString} from 'uint8array-extras'
1819

1920
const prefix = 'keybase://'
2021
export const linkIsKeybaseLink = (link: string) => link.startsWith(prefix)
@@ -112,7 +113,7 @@ const ServiceDecoration = (p: Props) => {
112113
// Parse JSON to get the type of the decoration
113114
let parsed: T.RPCChat.UITextDecoration
114115
try {
115-
const jsonString = Buffer.from(json, 'base64').toString()
116+
const jsonString = uint8ArrayToString(base64ToUint8Array(json))
116117
parsed = JSON.parse(jsonString)
117118
} catch (e) {
118119
return null

shared/common-adapters/plain-input.desktop.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import pick from 'lodash/pick'
55
import logger from '../logger'
66
import {checkTextInfo} from './input.shared'
77
import type {InternalProps, TextInfo, Selection} from './plain-input'
8+
import {stringToUint8Array} from 'uint8array-extras'
89

910
const maybeParseInt = (input: string | number, radix: number): number =>
1011
typeof input === 'string' ? parseInt(input, radix) : input
@@ -30,7 +31,7 @@ class PlainInput extends React.PureComponent<InternalProps> {
3031
_onChange = ({target: {value = ''}}) => {
3132
if (this.props.maxBytes) {
3233
const {maxBytes} = this.props
33-
if (Buffer.byteLength(value) > maxBytes) {
34+
if (stringToUint8Array(value).byteLength > maxBytes) {
3435
return
3536
}
3637
}

0 commit comments

Comments
 (0)