NanoRPC is a lightweight RPC framework designed for embedded systems and resource-constrained environments.
The nanorpc package provides efficient binary protocol communication using
Protocol Buffers with nanopb for embedded C targets and Go for
server/client applications. It is optimised for memory-constrained devices
while maintaining flexibility for standard server environments.
- Embedded-friendly: Optimized for resource-constrained environments
- Binary protocol: Efficient serialization using Protocol Buffers
- Multi-language support: C (via nanopb) and Go implementations
- Pub/sub messaging: Subscription-based updates with filtering
- Hash-based paths: Reduced memory usage for embedded targets
- Flexible connectivity: TCP and UNIX socket support
- Reconnection handling: Automatic client reconnection logic
- Zero-copy: Efficient message handling where possible
The nanorpc protocol supports multiple communication patterns:
- Ping-Pong: Health checks and connection validation
- Request-Response: Synchronous RPC calls with structured responses
- Pub/Sub: Event-driven messaging with subscription filtering
- Request types:
TYPE_PING,TYPE_REQUEST,TYPE_SUBSCRIBE - Response types:
TYPE_PONG,TYPE_RESPONSE,TYPE_UPDATE - Status codes:
STATUS_OK,STATUS_NOT_FOUND,STATUS_INTERNAL_ERROR
See NANORPC_PROTOCOL.md for the complete protocol specification.
The nanorpc protocol definitions are available on the Buf Schema Registry:
# buf.yaml
version: v2
deps:
- buf.build/protomcp/nanorpc # Includes nanopb dependencyThen import in your proto files:
import "nanorpc.proto";
service MyService {
rpc GetData(GetDataRequest) returns (GetDataResponse) {
option (nanorpc).request_path = "/api/data";
}
}Alternatively, download proto files from the repository for use with protoc.
The pkg/nanorpc/client package provides a complete Go
client implementation with:
- Connection management and automatic reconnection
- Request/response handling with correlation IDs
- Subscription management with callback support
- Hash-based path optimization for embedded systems
- Thread-safe operation with request queuing
- Comprehensive error handling
Integration with nanopb for embedded C applications with helpers for nanopb generation (C code) - implementation planned.
The pkg/nanorpc/server package provides a complete Go
server implementation with decoupled architecture design:
- Clean separation of concerns (Listener, SessionManager, MessageHandler)
- Request/response and ping-pong protocol support
- Extensible message handling with RequestContext
- Graceful shutdown and session management
- Comprehensive test coverage
The pkg/generator package provides utilities for
generating Protocol Buffer code (implementation planned).
The pkg/nanorpc package provides shared types and utilities:
- Protocol buffer definitions and generated code
- Hash cache implementation for path hashing
- Request/response encoding and decoding utilities
- Type aliases for protocol buffer internals
Note: This section is for nanorpc development. To use nanorpc in your project, see "Using NanoRPC in Your Project" above.
You need Go 1.23 or later. The project uses protoc and a comprehensive Makefile for all development tasks.
make # Equivalent to 'make all'
make all # Full build cycle: get deps, generate, tidy, buildIMPORTANT: Always run make all coverage before committing changes.
make test # Run tests
make coverage # Generate coverage reports
make all coverage # Full build with coverage (required before commits)make tidy # Format code and fix issues
make clean # Remove build artifacts
make up # Update dependencies
make lint # Run linting (included in 'make tidy')For development guidelines, please refer to AGENTS.md.
See LICENCE.txt for licensing information.