{"id":29471900,"url":"https://github.com/tokenclt/copra","last_synced_at":"2025-07-27T16:34:11.356Z","repository":{"id":62438939,"uuid":"112562531","full_name":"tokenclt/copra","owner":"tokenclt","description":"An RPC framework written in Rust.","archived":false,"fork":false,"pushed_at":"2018-04-07T13:51:23.000Z","size":181,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-04T22:40:51.250Z","etag":null,"topics":["network-programming","rpc","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tokenclt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-30T03:58:54.000Z","updated_at":"2018-11-10T12:14:25.000Z","dependencies_parsed_at":"2022-11-01T21:49:20.589Z","dependency_job_id":null,"html_url":"https://github.com/tokenclt/copra","commit_stats":null,"previous_names":["aprlirainkun/copra"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tokenclt/copra","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokenclt%2Fcopra","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokenclt%2Fcopra/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokenclt%2Fcopra/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokenclt%2Fcopra/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tokenclt","download_url":"https://codeload.github.com/tokenclt/copra/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tokenclt%2Fcopra/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265304536,"owners_count":23743880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["network-programming","rpc","rust"],"created_at":"2025-07-14T14:02:09.417Z","updated_at":"2025-07-14T14:04:28.067Z","avatar_url":"https://github.com/tokenclt.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"RPC framework in Rust\n\n[![Build Status](https://travis-ci.org/AprliRainkun/copra.svg?branch=master)](https://travis-ci.org/AprliRainkun/copra)\n[![Crates.io](https://img.shields.io/crates/v/copra.svg)](https://crates.io/crates/copra)\n\n`copra` is an [RPC] framework aimed at ease of use and configuration.\nIt can generate most of the boilerplate code in server and client side.\nYou only need to implement the core logic of services.\n\n[RPC]: https://en.wikipedia.org/wiki/Remote_procedure_call\n\n## Installation\n\n### Protocol compiler installation\n\n`copra` uses [Protocol Buffers][protobuf] (a.k.a. protobuf) to exchange messages\nand describe service signatures. The message and service descriptions are written\nin `.proto` files, and `copra` depends on the protocol compiler to generate rust\ncode from these files.\n\nVisit [this website] and download\n`proto-3.*.*-your-arch.zip` (`copra` needs protocol version 3), extract the\n`protoc` executable to a folder you like, then add `protoc` to your `PATH`.\n\n[protobuf]: https://developers.google.com/protocol-buffers/\n[this website]: https://github.com/google/protobuf/releases\n\n### Cargo setup\n\nAdd this to your `Cargo.toml`:\n\n```toml\n[dependencies]\ncopra = \"0.1\"\nfutures = \"0.1\"\ntokio-core = \"0.1\"\n\n[build-dependencies]\nprotoc-rust-copra = \"0.1\"\n```\n\n## Quick start\n\nHere is an example of implementing an echo RPC. First, create a file named\n`echo.proto` and put it in the manifest directory (i.e. next to `Cargo.toml`).\nPopulate it with:\n\n```protobuf\nsyntax = \"proto3\"\n\nmessage EchoMessage {\n    string msg = 1;\n}\n\n// Our echo service contains two method. One is sending back the original string\n// directly, and the other is returning the string in reversed form.\nservice Echo {\n    rpc echo(EchoMessage) returns (EchoMessage);\n    rpc reverse_echo(EchoMessage) returns (EchoMessage);\n}\n```\n\nNext, create a [`build.rs`][build-scripts] in the manifest directory, and add this to\nit:\n\n```rust\nextern crate protoc_rust_copra;\n\nfn main() {\n    protoc_rust_copra::run(protoc_rust_copra::Args {\n        out_dir: \"src/protos\",\n        input: \u0026[\"echo.proto\"],\n        includes: \u0026[],\n        rust_protobuf: true\n    }).expect(\"Failed to compile proto files\");\n}\n```\n\nThis will generate file `echo.rs` and `echo_copra.rs` in `src/protos`.\n\nThen, add this to `main.rs`:\n\n```rust\nextern crate copra;\nextern crate futures;\nextern crate tokio_core;\n\nuse copra::{ChannelBuilder, Controller, MethodError, ServerBuilder, ServiceRegistry};\nuse futures::future::{self, Future, FutureResult};\nuse std::thread;\nuse tokio_core::reactor::Core;\n\nuse protos::echo::EchoMessage;\nuse protos::echo_copra::{EchoRegistrant, EchoService, EchoStub};\n\nmod protos;\n\n// Service provider must implement Clone\n#[derive(Clone)]\nstruct Echo;\n\n// EchoService is a trait for defining service logic\n// It is generated by protoc-rust-copra\nimpl EchoService for Echo {\n    type EchoFuture = FutureResult\u003c(EchoMessage, Controller), MethodError\u003e;\n\n    type ReverseEchoFuture = FutureResult\u003c(EchoMessage, Controller), MethodError\u003e;\n\n    fn echo(\u0026self, (req, ctrl): (EchoMessage, Controller)) -\u003e Self::EchoFuture {\n        let mut response = EchoMessage::new();\n        response.set_msg(req.msg);\n        future::ok((response, ctrl))\n    }\n\n    fn reverse_echo(\n        \u0026self,\n        (req, ctrl): (EchoMessage, Controller)\n    ) -\u003e Self::ReverseEchoFuture {\n        let rev: String = req.msg.chars().rev().collect();\n        let mut response = EchoMessage::new();\n        response.set_msg(rev);\n        future::ok((response, ctrl))\n    }\n}\n\nfn main() {\n    let addr = \"127.0.0.1:8989\";\n\n    // server side\n    thread::spawn(move || {\n        // register the service provider, so that it can be accessed\n        let registrant = EchoRegistrant::new(Echo);\n        let mut registry = ServiceRegistry::new();\n        registry.register_service(registrant);\n\n        let server = ServerBuilder::new(addr, registry).build().unwrap();\n        server.start();\n    });\n\n    // client side\n    let mut core = Core::new().unwrap();\n    let handle = core.handle();\n    let channel = core.run(ChannelBuilder::single_server(addr, handle).build())\n        .unwrap();\n    let stub = EchoStub::new(\u0026channel);\n\n    let mut request = EchoMessage::new();\n    request.set_msg(\"Hello world\".to_string());\n\n    let (response, _info) = core.run(stub.echo(request.clone())).unwrap();\n    println!(\"{}\", response.msg);\n\n    let (response, _info) = core.run(stub.reverse_echo(request)).unwrap();\n    println!(\"{}\", response.msg);\n}\n```\n\nFinally, build and run this example by executing:\n\n```bash\n$ cargo build\n$ cargo run\n```\n\nMore examples can be found in `copra-examples`.\n\n[build-scripts]: https://doc.rust-lang.org/cargo/reference/build-scripts.html\n\n## Project structure\n\n* `copra`: main crate\n* `copra-compile`: generate protobuf runtime code used in the main `copra` crate\n* `copra-examples`: runnable examples\n* `protoc-rust-copra`: codegen for copra\n\n## Note\n\nThis project is still in the early development stage. It basically works, but \nyou should use it with caution. Any form of contribution is appreciated.\n\n## License\n\ncopra is free and open source software distributed under the terms of both the\n[MIT License] and the [Apache License 2.0].\n\n## Change log\n### `copra`\n\n* v0.1.1: Add homepage and documentation in cargo manifest files.\n\n### `protoc-rust-copra`\n\n* v0.1.1: Add homepage and documentation in cargo manifest files.\n\n[MIT License]: LICENSE-MIT\n[Apache License 2.0]: LICENSE-APACHE\n\n## Acknowledgement\n\nThis project is inspired by the [brpc] framework developped by Baidu Inc. copra\nhas similar interface and message protocol to brpc framework.\n\n[brpc]: https://github.com/brpc/brpc\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokenclt%2Fcopra","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftokenclt%2Fcopra","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftokenclt%2Fcopra/lists"}