### Development Commands Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Install dependencies, run unit tests, and launch the example app for development. The tests include native fuzz harnesses. ```sh bun install bun run test # unit tests + native ASan/UBSan fuzz harness (when toolchain present) bun run ios # run the example app ``` -------------------------------- ### Android Emulator Setup for Nitro Protobuf Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/ANALYSIS.md Steps to set up and run the Android emulator for testing Nitro Protobuf crash scenarios. Includes starting the emulator and filtering logcat output. ```bash bun run android adb logcat -v threadtime | grep -iE 'nitro|protobuf|fatal|sigsegv|abort|debug' ``` -------------------------------- ### Local Development Commands Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/CONTRIBUTING.md Essential commands for local development, including installing dependencies, running tests, linting, formatting, and launching the example app. ```sh bun install ``` ```sh bun run test # unit + native fuzz (when protoc/nanopb/clang present) ``` ```sh bun run lint-ci # eslint ``` ```sh bun run format:check # prettier ``` ```sh bun run ios # run the example app ``` -------------------------------- ### Install Protobuf and Nanopb (Bash) Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/ANALYSIS.md Installs protobuf and nanopb using Homebrew if they are missing on a macOS environment. ```bash brew install protobuf nanopb ``` -------------------------------- ### Run On-Device Benchmark Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/PERFORMANCE.md Execute the on-device benchmark for Release builds. This involves building the example, installing it, and tapping 'Run benchmark' in the app. Performance results are displayed on-screen and captured via an agent-device snapshot. ```bash # 3. On-device (Release): build, install, tap "Run benchmark" in the example. # The full ops/sec table renders on screen (read via agent-device snapshot # --json); see bench/results-ondevice.txt for the captured runs. ``` -------------------------------- ### Install react-native-nitro-protobuf Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Install the library and its peer dependency. For iOS, run pod install after installation. ```sh npm install @klaappinc/react-native-nitro-protobuf react-native-nitro-modules ``` ```sh cd ios && pod install ``` -------------------------------- ### Generate Nanopb Sources Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/example/README.md Run this command from the repository root to install dependencies and generate Nanopb sources for local protos. ```sh cd example npm install npm run proto:generate ``` -------------------------------- ### Build and Run iOS App Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/example/README.md Build and run the iOS application using npm or Yarn after installing CocoaPods dependencies and starting the Metro bundler. ```sh # Using npm npm run ios # OR using Yarn yarn ios ``` -------------------------------- ### iOS Simulation Setup for Nitro Protobuf Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/ANALYSIS.md Steps to set up and run the iOS simulator for testing Nitro Protobuf crash scenarios. Includes attaching the debugger and exercising specific failure cases. ```bash cd ~/projects/react-native-nitro-protobuf bun run example:install cd example/ios && pod install && cd - bun run ios ``` -------------------------------- ### Build and Test Commands (Bash) Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/ANALYSIS.md Commands for type checking, nitrogen regeneration, and native round-trip testing. Ensure protoc and nanopb are installed for native testing. ```bash bun run typecheck # TS bun run specs # nitrogen regen bun run test # native round-trip (needs protoc + nanopb + c++) ``` -------------------------------- ### Run Native C++ Microbenchmark Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/PERFORMANCE.md Execute the native C++ microbenchmark for performance testing. This requires protoc, protoc-gen-nanopb, and clang++ to be installed. ```bash # 1. Native C++ microbench (needs protoc + protoc-gen-nanopb + clang++) node bench/run-native.mjs # -> bench/results-native.json ``` -------------------------------- ### Install CocoaPods Dependencies for iOS Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/example/README.md Install CocoaPods dependencies for iOS development. Run 'bundle install' once to install the bundler, then 'bundle exec pod install' after updating native dependencies. ```sh bundle install bundle exec pod install ``` -------------------------------- ### Build and Run Android App Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/example/README.md Build and run the Android application using npm or Yarn after starting the Metro bundler. ```sh # Using npm npm run android # OR using Yarn yarn android ``` -------------------------------- ### Start Metro Bundler Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/example/README.md Start the Metro JavaScript bundler from the root of your React Native project to serve the application. ```sh # Using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Scaffold Project and Generate Code Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Initialize the project structure, define proto messages, and generate C sources, registry, and TypeScript types. Rebuild with generated code by running pod install. ```sh npx react-native-nitro-protobuf init # scaffold proto/, config, and a script #edit proto/*.proto … npm run proto:generate # generate C sources, registry, and TS types cd ios && pod install # (re)build with the generated code ``` -------------------------------- ### ProtobufCodec.cpp Type Marshalling Helpers Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/ANALYSIS.md Illustrates the type marshalling logic used in `ProtobufCodec.cpp`. The `get*Value` helpers pattern-match `std::variant` to handle different data types. ```cpp // Type marshalling done by get*Value(AnyValue&, T&) helpers that pattern-match the std::variant. ``` -------------------------------- ### Define Protobuf Message Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Define a message structure using Protocol Buffers syntax. This example defines a User message with various field types. ```proto // proto/example.proto syntax = "proto3"; package acme; message User { uint32 id = 1; string name = 2; repeated int32 scores = 3; bool active = 4; } ``` -------------------------------- ### Run Protobuf.js vs JSON Benchmark on Node Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/PERFORMANCE.md Execute the benchmark comparing protobuf.js and JSON performance on a Node.js environment. ```bash # 2. protobuf.js vs JSON on node node bench/js-bench.mjs # -> bench/results-js.json ``` -------------------------------- ### Configure Protobuf Generation Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Optional configuration file for protobuf generation. CLI flags override these settings. Defines output directories and default field limits. ```json { "protoDir": "proto", "tsOut": "./generated", "defaults": { "maxLength": 256, "maxSize": 256, "maxCount": 16 } } ``` -------------------------------- ### CLI Commands for react-native-nitro-protobuf Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Use these commands to scaffold proto files, configuration, and generate code. The 'generate' command is the default and creates nanopb sources, registry, and TypeScript types. ```bash react-native-nitro-protobuf [options] Commands: init Scaffold proto/, config, and a generate script generate Generate nanopb sources, registry, and TS types (default) Options: --protoDir Directory with .proto files (default: ./proto) --outDir Output for generated C/registry (default: /generated) --tsOut Output for generated TS types (default: outDir) --protoPath Extra protoc import path (repeatable) --protoc Use a specific protoc (default: bundled) --nanopb Use a specific protoc-gen-nanopb (default: auto-installed) --strict Require explicit .options for every static field ``` -------------------------------- ### Architecture Overview of NitroProtobuf Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/ANALYSIS.md Illustrates the interaction between JavaScript (React Native), JSI, HybridProtobuf, and Nanopb. Useful for understanding data flow and component responsibilities. ```text ┌─────────────────── JS (React Native) ────────────────────┐ │ NitroProtobuf.encode(name, AnyMap) -> ArrayBuffer │ │ NitroProtobuf.decode(name, ArrayBuffer) -> AnyMap │ │ NitroProtobuf.listMessages() -> string[] │ └──────────────────────────┬───────────────────────────────┘ │ JSI (sync, JS thread) ┌──────────────────────────▼───────────────────────────────┐ │ HybridProtobuf::{encode,decode,listMessages} │ │ → getMessageInfo(name) → ProtobufRegistry │ │ → encodeMessage / decodeMessage (ProtobufCodec.cpp) │ │ → walk AnyMap, pb_field_iter_*, write to │ │ static C struct, then pb_encode / pb_decode │ └──────────────────────────┬───────────────────────────────┘ │ Nanopb (vendored under cpp/nanopb) ▼ wire-format bytes ``` -------------------------------- ### ProtobufCodec.cpp encodeMessage internal logic Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/ANALYSIS.md Details the internal workings of `ProtobufCodec.cpp` for encoding messages. It shows how the JS object is walked and matched against nanopb fields for encoding. ```cpp // populateMessage(info, struct*, AnyObject) walks every key in the JS-supplied object, finds matching nanopb field via `pb_field_iter_find(tag)`, writes scalar via `memcpy`, recurses for sub-messages. ``` -------------------------------- ### Branching Strategy Visualization Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/CONTRIBUTING.md Visual representation of the Git branching model used in the project, illustrating feature and hotfix flows. ```sh feature/x ─┐ feature/y ─┼─▶ develop ─────▶ main ─▶ (Release + npm publish) hotfix/z ──────────────────▶ main ─┘ └─▶ back-merge to develop ``` -------------------------------- ### Override Field Size Limits Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Specify custom field size limits in a .options file next to your .proto file. These override the global defaults. ```proto acme.User.name max_length: 32 acme.User.avatar max_size: 1024 ``` -------------------------------- ### Expo Configuration Plugin Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Add the Expo config plugin to app.json to integrate with Expo projects. Regenerates on expo prebuild. ```json { "plugins": [["@klaappinc/react-native-nitro-protobuf", { "protoDir": "proto" }]] } ``` -------------------------------- ### ProtobufCodec.cpp decodeMessage internal logic Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/ANALYSIS.md Explains the internal process for decoding messages within `ProtobufCodec.cpp`. It iterates through declared `FieldInfo` to read each field and construct the `AnyMap`. ```cpp // decodeMessageInternal(info, struct*) iterates declared FieldInfo array, reads each field, builds AnyMap. ``` -------------------------------- ### Use Generated Typed API Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Import and use the generated, fully-typed encode and decode functions for your protobuf messages. Assumes generated types are in './generated/nitro-protobuf'. ```ts import { encode, decode, type AcmeUser } from './generated/nitro-protobuf' const user: AcmeUser = { id: 1, name: 'Ada', scores: [10, 20], active: true } const bytes = encode('acme.User', user) // ArrayBuffer const back = decode('acme.User', bytes) // AcmeUser ``` -------------------------------- ### Encode, Decode, and List Messages in TypeScript Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/README.md Import and use the NitroProtobuf object for type-safe encoding and decoding of messages. Ensure the message name string matches your .proto definition. ```typescript import { NitroProtobuf } from '@klaappinc/react-native-nitro-protobuf' const bytes = NitroProtobuf.encode('acme.User', { id: 1, name: 'Ada' }) const user = NitroProtobuf.decode('acme.User', bytes) const names = NitroProtobuf.listMessages() ``` -------------------------------- ### Create Feature Branch Source: https://github.com/klaappinc/react-native-nitro-protobuf/blob/develop/CONTRIBUTING.md Commands to create a new feature branch from the develop branch. Ensure you pull the latest changes before branching. ```sh git switch develop && git pull git switch -c feature/my-thing ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.