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.
📦 Installation
Add this to your Cargo.toml:
[]
= "0.2.3"
= { = "1", = ["full"] }
= "1"
🚀 High-Level Usage
The primary entry point is the [GrancClient]. It acts as an orchestrator that:
- Connects to a gRPC server.
- Resolves the schema (either from a local file or via Server Reflection).
- Determines the method type (Unary, Server Streaming, etc.).
- Execute the request using JSON.
Example: Making a Dynamic Call
use ;
use json;
async
🛠️ 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 (e.g., client.say_hello(HelloRequest)).
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, providing specific methods for all four gRPC access patterns:
unaryserver_streamingclient_streamingbidirectional_streaming
use GrpcClient;
// You need a method_descriptor from prost_reflect::DescriptorPool
// let method_descriptor = ...;
let mut grpc = new;
let result = grpc.unary.await?;
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.
- Encoder: Validates
serde_json::Valueagainst the inputMessageDescriptorand serializes it. - Decoder: Deserializes bytes into a
DynamicMessageand converts it back toserde_json::Value.
3. ReflectionClient
A client for grpc.reflection.v1. It enables runtime schema discovery.
The ReflectionClient is smart enough to handle dependencies. When you ask for a symbol (e.g., my.package.Service),
it recursively fetches the file defining that symbol and all its transitive imports, building a complete prost_types::FileDescriptorSet ready for use.
use ReflectionClient;
let mut reflection = new;
let fd_set = reflection.file_descriptor_set_by_symbol.await?;
You can then build a prost_reflect::DescriptorPool with the returned prost_types::FileDescriptorSet to be able to inspect in detail the descriptor.
⚖️ License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.