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

Tauri 2.0 Zero-Copy Binary IPC Protocol for High-Throughput Mobile Sensor Streams

Enforces zero-copy byte buffer transfers via Tauri 2.0 IPC Response primitives instead of Serde JSON or Base64 serialization for high-frequency telemetry and sensor feeds. Eliminates serialization overhead, V8 garbage collection thrashing, and memory bloat on resource-constrained iOS and Android WebViews.

Prohibited Anti-Pattern: Serializing High-Frequency Binary Sensor Telemetry into JSON Arrays or Base64 Strings Across IPC

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Zero-Copy Binary IPC Protocol for High-Throughput Mobile Sensor Streams - Enforces zero-copy byte buffer transfers via Tauri 2.0 IPC Response primitives instead of Serde JSON or Base64 serialization for high-frequency telemetry and sensor feeds. Eliminates serialization overhead, V8 garbage collection thrashing, and memory bloat on resource-constrained iOS and Android WebViews.
globs: src-tauri/src/**/*.rs, src/**/*.{ts,tsx}
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri-2-zero-copy-binary-ipc-guardrail"
---

# Tauri 2.0 Zero-Copy Binary IPC Protocol for High-Throughput Mobile Sensor Streams

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: Serializing High-Frequency Binary Sensor Telemetry into JSON Arrays or Base64 Strings Across IPC

## System Constraints
You are a Principal Mobile Systems Architect enforcing Tauri 2.0 binary IPC invariants. You mandate zero-copy or minimal-copy binary byte streams for all sensor, audio, and camera telemetry crossing the Rust-to-Webview boundary. Forbid any intermediate Base64 encoding or Serde JSON array serialization across mobile IPC boundaries.

## Strict Guidelines
- Engineers MUST ALWAYS return raw binary data using `tauri::ipc::Response::new(bytes)` in Tauri 2.0 command handlers for high-throughput feeds (>60Hz or >64KB payloads).
- Engineers MUST NOT serialize numeric buffers into Serde JSON arrays (`Vec<u8>`, `Vec<f32>`) or convert buffers to Base64 strings for IPC transport.
- Frontend consumers MUST invoke binary commands using typed ArrayBuffer return expectations and construct TypedArrays (`Float32Array`, `Uint8Array`) directly on the underlying ArrayBuffer.
- Services MUST recycle or detach ArrayBuffers where possible to prevent heap fragmentation in mobile JavaScript runtimes (WebKit JavaScriptCore on iOS, V8 on Android).
- Components NEVER re-encode binary payloads into JSON strings when dispatching to state stores or web workers; use `structuredClone` with transfer lists or direct TypedArray references.

## Bad vs Good Implementations
### High-Throughput Sensor Ingest: JSON/Base64 Anti-Pattern vs. Tauri 2.0 Raw IPC Response

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Returning `Vec<f32>` through standard Tauri command serialization causes Rust Serde to emit an ASCII JSON array. On mobile, this expands a compact 4KB binary payload into ~40KB of JSON text, forcing expensive string allocations and JSON parsing in JavaScriptCore/V8 at 60-120Hz.
```typescript
// Rust: #[tauri::command] fn read_imu_telemetry() -> Vec<f32> { ... }
// Anti-pattern: Tauri serializes Vec<f32> into a massive JSON array of numbers `[0.123, -0.456, ...]`
import { invoke } from '@tauri-apps/api/core';

interface SensorFrame {
  samples: number[];
}

export async function pollSensorBatch(): Promise<Float32Array> {
  // Triggers heavy JSON.parse() on every tick, causing micro-stutters and mobile battery drain
  const samples = await invoke<number[]>('read_imu_telemetry');
  return new Float32Array(samples);
}
```

#### Production Standard (Correct)
> **Standard**: Using `tauri::ipc::Response::new` delivers the raw byte slice directly to the WebView IPC interface without stringification. The frontend receives an `ArrayBuffer` and instantiates a typed `Float32Array` view over it with zero serialization or allocation overhead.
```typescript
// Rust backend:
// #[tauri::command]
// pub fn read_imu_telemetry() -> tauri::ipc::Response {
//     let raw_bytes: Vec<u8> = acquire_sensor_bytes(); // Direct hardware DMA / ring buffer
//     tauri::ipc::Response::new(raw_bytes)
// }

import { invoke } from '@tauri-apps/api/core';

export async function pollSensorBatch(): Promise<Float32Array> {
  // Tauri 2.0 returns raw ArrayBuffer when the command returns tauri::ipc::Response
  const rawBuffer = await invoke<ArrayBuffer>('read_imu_telemetry');
  
  // Zero-copy view directly on top of the transferred Webview ArrayBuffer
  return new Float32Array(rawBuffer);
}
```

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: Tauri 2.0 Zero-Copy Binary IPC Protocol for High-Throughput Mobile Sensor Streams

Tauri 2.0 Zero-Copy Binary IPC Protocol for High-Throughput Mobile Sensor Streams defines an industrial-grade behavioral standard for mobile engineering. Enforces zero-copy byte buffer transfers via Tauri 2.0 IPC Response primitives instead of Serde JSON or Base64 serialization for high-frequency telemetry and sensor feeds. Eliminates serialization overhead, V8 garbage collection thrashing, and memory bloat on resource-constrained iOS and Android WebViews. 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 High-Frequency Binary Sensor Telemetry into JSON Arrays or Base64 Strings Across IPC 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 High-Frequency Binary Sensor Telemetry into JSON Arrays or Base64 Strings Across IPCCritical
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 raw binary data using `tauri

Engineers MUST ALWAYS return raw binary data using `tauri::ipc::Response::new(bytes)` in Tauri 2.0 command handlers for high-throughput feeds (>60Hz or >64KB payloads).

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 serialize numeric buffers into Serde JSON arrays (`Vec<u8>`, `Vec<f32>`) or convert buffers to Base64 strings for IPC transport.

Engineers MUST NOT serialize numeric buffers into Serde JSON arrays (`Vec<u8>`, `Vec<f32>`) or convert buffers to Base64 strings for IPC transport.

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 typed ArrayBuffer return expectations and construct TypedArrays (`Float32Array`, `Uint8Array`) directly on the underlying ArrayBuffer.

Frontend consumers MUST invoke binary commands using typed ArrayBuffer return expectations and construct TypedArrays (`Float32Array`, `Uint8Array`) directly on the underlying ArrayBuffer.

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

Services MUST recycle or detach ArrayBuffers where possible to prevent heap fragmentation in mobile JavaScript runtimes (WebKit JavaScriptCore on iOS, V8 on Android).

Services MUST recycle or detach ArrayBuffers where possible to prevent heap fragmentation in mobile JavaScript runtimes (WebKit JavaScriptCore on iOS, V8 on Android).

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 re-encode binary payloads into JSON strings when dispatching to state stores or web workers

Components NEVER re-encode binary payloads into JSON strings when dispatching to state stores or web workers; use `structuredClone` with transfer lists or direct TypedArray references.

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 Tauri 2.0 Zero-Copy Binary IPC Protocol for High-Throughput Mobile Sensor Streams critical for AI coding assistants?

Enforces zero-copy byte buffer transfers via Tauri 2.0 IPC Response primitives instead of Serde JSON or Base64 serialization for high-frequency telemetry and sensor feeds. Eliminates serialization overhead, V8 garbage collection thrashing, and memory bloat on resource-constrained iOS and Android WebViews. 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 High-Frequency Binary Sensor Telemetry into JSON Arrays or Base64 Strings Across IPC) 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

Tauri