Granc Core
granc-core is the foundational library powering the Granc CLI. It provides a dynamic gRPC client capability that allows you to interact with any gRPC server without needing compile-time Protobuf code generation.
Instead of strictly typed Rust structs, this library bridges standard serde_json::Value payloads directly to Protobuf binary wire format at runtime.
🚀 High-Level Usage
The primary entry point is the [GrancClient]. It uses a Typestate Pattern to ensure safety and correctness regarding how the Protobuf schema is resolved. There are three distinct states:
- [
Online]: Connected to a server, uses Server Reflection (Async introspection). - [
OnlineWithoutReflection]: Connected to a server, uses a localFileDescriptorSet(Sync introspection). - [
Offline]: Disconnected, uses a localFileDescriptorSet(Sync introspection).
1. Online (Server Reflection)
This is the default state when you connect. The client queries the server's reflection endpoint to dynamically discover services and message formats.
use ;
use json;
async
2. OnlineWithoutReflection (Local Schema)
Use this state if you are connecting to a server that does not support reflection, or if you want to enforce a specific schema version from a local file.
use GrancClient;
async
3. Offline (Introspection Only)
This state is useful for building tools that need to inspect .bin descriptor files without establishing a network connection.
use GrancClient;
🛠️ Internal Components
We expose the internal building blocks of granc for developers who need more granular control or want to build their own tools on top of our dynamic transport layer.
1. GrpcClient (Generic Transport)
Standard tonic clients are strongly typed. GrpcClient is a generic wrapper around tonic::client::Grpc that works strictly with serde_json::Value and prost_reflect::MethodDescriptor. It handles the raw HTTP/2 path construction and metadata mapping.
2. JsonCodec
The magic behind the dynamic serialization. This implementation of tonic::codec::Codec validates and transcodes JSON to Protobuf bytes (and vice versa) on the fly.
3. ReflectionClient
A robust client for grpc.reflection.v1. It automatically handles transitive dependency resolution, recursively fetching all imported files to build a complete, self-contained FileDescriptorSet.
⚖️ License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.