This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
mobilecritical PriorityID: tauri2-zero-copy-shared-memory-ipc-protocol

Tauri 2.0 Binary IPC Protocol & Zero-Copy Memory Slice Enforcement

Enforces raw binary ArrayBuffer transfers and memory-mapped byte slices over the Tauri 2.0 IPC bridge for high-frequency telemetry and binary streams. Eliminates serde_json serialization overhead and GC thrashing across the Rust core and mobile WebKit/Chromium WebView boundary.

Prohibited Anti-Pattern: JSON-Serialized Telemetry and High-Frequency Bridge Flooding

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Tauri 2.0 Binary IPC Protocol & Zero-Copy Memory Slice Enforcement - Enforces raw binary ArrayBuffer transfers and memory-mapped byte slices over the Tauri 2.0 IPC bridge for high-frequency telemetry and binary streams. Eliminates serde_json serialization overhead and GC thrashing across the Rust core and mobile WebKit/Chromium WebView boundary.
globs: src/**/*.{ts,tsx}, src-tauri/src/**/*.rs
alwaysApply: true
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/tauri2-zero-copy-shared-memory-ipc-protocol"
---

# Tauri 2.0 Binary IPC Protocol & Zero-Copy Memory Slice Enforcement

> **Severity**: CRITICAL | **Category**: mobile
> **Anti-Pattern Warning**: JSON-Serialized Telemetry and High-Frequency Bridge Flooding

## System Constraints
You are a Principal Systems and Mobile Architect enforcing zero-copy binary IPC invariants for Tauri 2.0 applications. You strictly prohibit passing telemetry, audio, video, sensor frames, or high-throughput tabular records over default serde_json bridge channels, mandating raw binary slices, typed array buffers, and direct memory views.

## Strict Guidelines
- Engineers MUST ALWAYS return `tauri::ipc::Response` containing raw byte vectors (`Vec<u8>`) or use custom protocol streaming for payloads exceeding 64KB or streams operating above 10Hz.
- Engineers MUST NOT serialize high-frequency telemetry arrays or binary buffers into JSON via `serde_json` or default Tauri command return types.
- Code SHOULD ingest binary responses directly into JavaScript `ArrayBuffer` instances and wrap them with typed array views (`Uint8Array`, `Float32Array`, `DataView`) without intermediate string decoding.
- Services MUST implement fixed-width binary memory layouts (little-endian aligned structs) to allow zero-copy direct view indexing on the WebView frontend.
- Components NEVER execute `JSON.parse` or string conversions on IPC channels designated for sensor, frame, or telemetry data pipelines.

## Bad vs Good Implementations
### Ingesting High-Frequency IMU/Sensor Telemetry via Tauri 2.0 IPC

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transporting numeric arrays via default JSON serialization incurs UTF-8 encoding in Rust, JSON parsing in JavaScript, and significant garbage collection thrashing on mobile WebViews, dropping frame rates under high-frequency polling.
```typescript
import { invoke } from '@tauri-apps/api/core';

interface ImuReading {
  timestamp: number;
  accelX: number;
  accelY: number;
  accelZ: number;
}

// ANTI-PATTERN: Serializing large numeric telemetry arrays over JSON bridge
// Causes massive CPU spikes, string allocations, and mobile WebView GC stutters at 60Hz+
export async function pollSensorBatch(): Promise<ImuReading[]> {
  const data = await invoke<ImuReading[]>('get_imu_telemetry_batch');
  return data;
}
```

#### Production Standard (Correct)
> **Standard**: Bypasses JSON deserialization completely by transporting a raw byte stream via Tauri 2.0 binary IPC and zero-copy mapping the underlying ArrayBuffer directly with typed views.
```typescript
import { invoke } from '@tauri-apps/api/core';

export interface ImuReading {
  timestamp: bigint;
  accelX: number;
  accelY: number;
  accelZ: number;
}

// INVARIANT: Request raw binary buffer; parse in-place with zero allocations via DataView
const BYTES_PER_RECORD = 20; // 8 bytes BigInt64 + 3 * 4 bytes Float32

export async function pollSensorBatch(): Promise<Float32Array> {
  const rawBuffer: ArrayBuffer = await invoke('get_imu_telemetry_binary', {}, {
    headers: { 'Content-Type': 'application/octet-stream' }
  });

  // Direct memory-mapped typed view over IPC ArrayBuffer without serialization
  return new Float32Array(rawBuffer);
}

export function readImuRecord(view: DataView, offset: number): ImuReading {
  return {
    timestamp: view.getBigInt64(offset, true),
    accelX: view.getFloat32(offset + 8, true),
    accelY: view.getFloat32(offset + 12, true),
    accelZ: view.getFloat32(offset + 16, true)
  };
}
```

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 Binary IPC Protocol & Zero-Copy Memory Slice Enforcement

Tauri 2.0 Binary IPC Protocol & Zero-Copy Memory Slice Enforcement defines an industrial-grade behavioral standard for mobile engineering. Enforces raw binary ArrayBuffer transfers and memory-mapped byte slices over the Tauri 2.0 IPC bridge for high-frequency telemetry and binary streams. Eliminates serde_json serialization overhead and GC thrashing across the Rust core and mobile WebKit/Chromium WebView boundary. 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: JSON-Serialized Telemetry and High-Frequency Bridge Flooding 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 DriftJSON-Serialized Telemetry and High-Frequency Bridge FloodingCritical
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` containing raw byte vectors (`Vec<u8>`) or use custom protocol streaming for payloads exceeding 64KB or streams operating above 10Hz.

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 high-frequency telemetry arrays or binary buffers into JSON via `serde_json` or default Tauri command return types.

Engineers MUST NOT serialize high-frequency telemetry arrays or binary buffers into JSON via `serde_json` or default Tauri command return types.

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

Code SHOULD ingest binary responses directly into JavaScript `ArrayBuffer` instances and wrap them with typed array views (`Uint8Array`, `Float32Array`, `DataView`) without intermediate string decoding.

Code SHOULD ingest binary responses directly into JavaScript `ArrayBuffer` instances and wrap them with typed array views (`Uint8Array`, `Float32Array`, `DataView`) without intermediate string decoding.

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 implement fixed-width binary memory layouts (little-endian aligned structs) to allow zero-copy direct view indexing on the WebView frontend.

Services MUST implement fixed-width binary memory layouts (little-endian aligned structs) to allow zero-copy direct view indexing on the WebView frontend.

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 execute `JSON.parse` or string conversions on IPC channels designated for sensor, frame, or telemetry data pipelines.

Components NEVER execute `JSON.parse` or string conversions on IPC channels designated for sensor, frame, or telemetry data pipelines.

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 Binary IPC Protocol & Zero-Copy Memory Slice Enforcement critical for AI coding assistants?

Enforces raw binary ArrayBuffer transfers and memory-mapped byte slices over the Tauri 2.0 IPC bridge for high-frequency telemetry and binary streams. Eliminates serde_json serialization overhead and GC thrashing across the Rust core and mobile WebKit/Chromium WebView boundary. 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 (JSON-Serialized Telemetry and High-Frequency Bridge Flooding) 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