AgentSkillsCN

tonic-client-reference

请参考LOCAL tonic/目录中的gRPC客户端实现模式。切勿使用WebFetch/WebSearch来获取github.com/hyperium/tonic——始终读取本地文件。

SKILL.md
--- frontmatter
name: tonic-client-reference
description: Reference the LOCAL tonic/ directory for gRPC client implementation patterns. NEVER use WebFetch/WebSearch for github.com/hyperium/tonic - always read local files.

tonic-client-reference

Reference the LOCAL tonic/ directory for understanding gRPC client implementation patterns in Rust.

CRITICAL: Use Local Files Only

NEVER fetch from GitHub. Do not use:

  • WebFetch with github.com/hyperium/tonic
  • WebFetch with raw.githubusercontent.com/.../tonic
  • WebSearch for "tonic" implementation details

ALWAYS use local files:

  • Read tool with tonic/**/*.rs paths
  • Grep tool with path="tonic/"
  • Glob tool with path="tonic/"

The tonic/ directory at the repository root is the authoritative reference.

Instructions

The tonic/ directory at the repository root contains the official Rust gRPC implementation.

Setup (one-time only)

If the directory doesn't exist, clone it once:

bash
git clone https://github.com/hyperium/tonic.git tonic

After cloning, ALWAYS use the local files via Read/Grep/Glob tools.

Key Files Reference

FilePurpose
tonic/tonic/src/client/grpc.rsMain gRPC client implementation
tonic/tonic/src/client/service.rsClient service wrapper
tonic/tonic/src/request.rsRequest wrapper with metadata
tonic/tonic/src/response.rsResponse wrapper with metadata
tonic/tonic/src/metadata/gRPC metadata (headers) handling
tonic/tonic/src/codec/Encoding/decoding traits and implementations
tonic/tonic/src/transport/channel/HTTP/2 channel and connection management
tonic/tonic/src/transport/channel/service/Tower service implementations
tonic/tonic/src/status.rsgRPC status codes and error handling
tonic/tonic/src/extensions.rsRequest/response extensions
tonic/tonic/src/body.rsHTTP body handling

Client-Specific Files

FilePurpose
tonic/tonic/src/transport/channel/endpoint.rsEndpoint builder and configuration
tonic/tonic/src/transport/channel/mod.rsChannel implementation
tonic/tonic/src/transport/channel/service/reconnect.rsReconnection logic
tonic/tonic/src/transport/channel/service/tls.rsTLS configuration
tonic/tonic/src/transport/service/grpc_timeout.rsTimeout handling

Codec/Streaming Files

FilePurpose
tonic/tonic/src/codec/decode.rsStreaming decoder implementation
tonic/tonic/src/codec/encode.rsStreaming encoder implementation
tonic/tonic/src/codec/compression.rsCompression handling
tonic/tonic/src/codec/buffer.rsBuffer management for streaming

Retry/Backoff Files

FilePurpose
tonic/grpc/src/client/name_resolution/backoff.rsExponential backoff implementation
tonic/tonic-types/src/richer_error/std_messages/retry_info.rsRetryInfo error detail type

Usage Patterns

Channel configuration:

code
Read tonic/tonic/src/transport/channel/endpoint.rs for Endpoint and Channel setup

Streaming implementation:

code
Read tonic/tonic/src/codec/decode.rs and encode.rs for streaming frame handling

Metadata handling:

code
Read tonic/tonic/src/metadata/map.rs for MetadataMap implementation

Error/Status handling:

code
Read tonic/tonic/src/status.rs for Status type and code mappings

Interceptors:

code
Read tonic/tonic/src/service/interceptor.rs for interceptor patterns

Retry/Backoff:

code
Read tonic/grpc/src/client/name_resolution/backoff.rs for exponential backoff with jitter

When to Use

  • Implementing client-side gRPC features
  • Understanding streaming patterns
  • Debugging connection or channel issues
  • Verifying correct metadata handling
  • Checking status code mappings
  • Understanding Tower service integration

How to Use (Examples)

bash
# Search for channel configuration
Grep pattern="Endpoint" path="tonic/tonic/src/transport/"

# Read client implementation
Read file_path="tonic/tonic/src/client/grpc.rs"

# Find streaming-related code
Grep pattern="Streaming" path="tonic/tonic/src/codec/"

# Search for interceptor patterns
Grep pattern="Interceptor" path="tonic/tonic/src/"

# Search for backoff/retry patterns
Grep pattern="backoff" path="tonic/grpc/src/client/"

FORBIDDEN:

  • WebFetch("https://github.com/hyperium/tonic/...") - NO
  • WebFetch("https://raw.githubusercontent.com/hyperium/tonic/...") - NO
  • WebSearch("tonic ...") for implementation details - NO
  • Guessing behavior without reading local tonic/**/*.rs files - NO