This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: tauri-v2-mobile-ipc-zero-copy-binary-transfer

Mandate Zero-Copy Binary ArrayBuffer Transfers for Tauri 2.0 Mobile IPC

High-frequency telemetry, media buffers, and sensor streams across the Tauri 2.0 Rust-webview boundary must bypass serde_json serialization in favor of raw binary byte slices and typed ArrayBuffers. Serializing binary payloads into JSON arrays or Base64 strings incurs severe memory allocation overhead, WebKit/Android WebView bridge serialization stalls, and catastrophic garbage collector thrashing on mobile hardware.

Prohibited Anti-Pattern: Serializing raw byte arrays and telemetry into JSON number vectors or Base64 over the mobile IPC bridge

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Mandate Zero-Copy Binary ArrayBuffer Transfers for Tauri 2.0 Mobile IPC - High-frequency telemetry, media buffers, and sensor streams across the Tauri 2.0 Rust-webview boundary must bypass serde_json serialization in favor of raw binary byte slices and typed ArrayBuffers. Serializing binary payloads into JSON arrays or Base64 strings incurs severe memory allocation overhead, WebKit/Android WebView bridge serialization stalls, and catastrophic garbage collector thrashing on mobile hardware.
globs: src/**/*.{ts,tsx}, src-tauri/src/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-v2-mobile-ipc-zero-copy-binary-transfer"
---

# Mandate Zero-Copy Binary ArrayBuffer Transfers for Tauri 2.0 Mobile IPC

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Serializing raw byte arrays and telemetry into JSON number vectors or Base64 over the mobile IPC bridge

## System Constraints
You are a Principal Mobile Architect enforcing Tauri 2.0 zero-copy binary IPC standards. Mandate that all high-frequency data (>=10Hz), telemetry, and binary payloads (>1KB) bypass serde_json serialization by using Tauri 2.0 raw binary responses (`tauri::ipc::Response`) on Rust commands and `invoke` with binary response types or custom protocol streaming on the TypeScript frontend.

## Strict Guidelines
- Engineers MUST ALWAYS return `tauri::ipc::Response` with raw binary bytes (`Vec<u8>`) in Rust instead of serializing byte buffers as `Vec<u8>` or JSON objects.
- Engineers MUST NOT transfer binary data across the IPC bridge encoded as Base64 strings or JSON integer arrays (`number[]`).
- Frontend consumers MUST invoke binary commands using `{ responseType: 'binary' }` or consume direct `ArrayBuffer` / `Uint8Array` views to eliminate string allocation in the JavaScript engine.
- High-frequency telemetry (e.g., IMU sensors, audio samples, frame buffers) MUST use Tauri 2.0 `Channel<tauri::ipc::InvokeResponseBody>` or continuous raw binary chunks rather than discrete JSON invoke calls.
- Components NEVER transform ArrayBuffer payloads into intermediate JSON objects within the UI rendering thread.

## Bad vs Good Implementations
### Tauri 2.0 Rust and TypeScript Binary IPC Protocol

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Returning a byte vector as standard JSON forces Tauri to serialize every byte as an integer token into an intermediate JSON string (e.g., '[12,34,56...]'). On iOS WKWebView and Android WebView, this causes bridge parsing stalls and severe GC thrashing at high frequencies.
```typescript
import { invoke } from '@tauri-apps/api/core';

// ANTI-PATTERN: Serializing byte stream as JSON number array or base64
interface TelemetryJsonPayload {
  sensorId: string;
  readings: number[]; // Serialized Vec<u8> produces massive JSON string overhead
}

export async function fetchSensorTelemetry(sensorId: string): Promise<Float32Array> {
  const response = await invoke<TelemetryJsonPayload>('get_sensor_telemetry', {
    sensorId,
  });
  // Forces GC thrashing: creates millions of JS number primitives from JSON parse
  return new Float32Array(new Uint8Array(response.readings).buffer);
}
```

#### Production Standard (Correct)
> **Standard**: Using Tauri 2.0's raw `tauri::ipc::Response` on the Rust side sends raw memory buffers directly across the native bridge. The TypeScript client receives an `ArrayBuffer` without intermediate string parsing, allowing zero-copy instantiation of `Float32Array`.
```typescript
import { invoke } from '@tauri-apps/api/core';

// PRODUCTION FIX: Transfer zero-copy raw memory slice via ArrayBuffer
export async function fetchSensorTelemetry(sensorId: string): Promise<Float32Array> {
  // In Tauri 2.0, requesting binary response yields raw Uint8Array/ArrayBuffer directly
  const rawBytes = await invoke<ArrayBuffer>('get_sensor_telemetry_raw', {
    sensorId,
  }, {
    headers: { 'Accept': 'application/octet-stream' }
  });

  // Zero-copy typed array view over the underlying ArrayBuffer memory slice
  return new Float32Array(rawBytes);
}

// Complementary Rust Implementation:
// #[tauri::command]
// pub fn get_sensor_telemetry_raw(sensor_id: String) -> tauri::ipc::Response {
//     let raw_telemetry: Vec<u8> = acquire_hardware_slice(&sensor_id);
//     tauri::ipc::Response::new(raw_telemetry)
// }
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Mandate Zero-Copy Binary ArrayBuffer Transfers for Tauri 2.0 Mobile IPC

Mandate Zero-Copy Binary ArrayBuffer Transfers for Tauri 2.0 Mobile IPC defines an industrial-grade behavioral standard for mobile engineering. High-frequency telemetry, media buffers, and sensor streams across the Tauri 2.0 Rust-webview boundary must bypass serde_json serialization in favor of raw binary byte slices and typed ArrayBuffers. Serializing binary payloads into JSON arrays or Base64 strings incurs severe memory allocation overhead, WebKit/Android WebView bridge serialization stalls, and catastrophic garbage collector thrashing on mobile hardware. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: Serializing raw byte arrays and telemetry into JSON number vectors or Base64 over the mobile IPC bridge Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftSerializing raw byte arrays and telemetry into JSON number vectors or Base64 over the mobile IPC bridgeCritical
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Engineers MUST ALWAYS return `tauri

Engineers MUST ALWAYS return `tauri::ipc::Response` with raw binary bytes (`Vec<u8>`) in Rust instead of serializing byte buffers as `Vec<u8>` or JSON objects.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Engineers MUST NOT transfer binary data across the IPC bridge encoded as Base64 strings or JSON integer arrays (`number[]`).

Engineers MUST NOT transfer binary data across the IPC bridge encoded as Base64 strings or JSON integer arrays (`number[]`).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Frontend consumers MUST invoke binary commands using `{ responseType

Frontend consumers MUST invoke binary commands using `{ responseType: 'binary' }` or consume direct `ArrayBuffer` / `Uint8Array` views to eliminate string allocation in the JavaScript engine.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

High-frequency telemetry (e.g., IMU sensors, audio samples, frame buffers) MUST use Tauri 2.0 `Channel<tauri

High-frequency telemetry (e.g., IMU sensors, audio samples, frame buffers) MUST use Tauri 2.0 `Channel<tauri::ipc::InvokeResponseBody>` or continuous raw binary chunks rather than discrete JSON invoke calls.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Components NEVER transform ArrayBuffer payloads into intermediate JSON objects within the UI rendering thread.

Components NEVER transform ArrayBuffer payloads into intermediate JSON objects within the UI rendering thread.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Mandate Zero-Copy Binary ArrayBuffer Transfers for Tauri 2.0 Mobile IPC critical for AI coding assistants?

High-frequency telemetry, media buffers, and sensor streams across the Tauri 2.0 Rust-webview boundary must bypass serde_json serialization in favor of raw binary byte slices and typed ArrayBuffers. Serializing binary payloads into JSON arrays or Base64 strings incurs severe memory allocation overhead, WebKit/Android WebView bridge serialization stalls, and catastrophic garbage collector thrashing on mobile hardware. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (Serializing raw byte arrays and telemetry into JSON number vectors or Base64 over the mobile IPC bridge) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related MOBILE Rules

View all rules →
1 Rule in Stack

Mandate