TarsCpp Documentation

repository·master·Indexed 19 days ago

https://github.com/tarscloud/tarscpp

TarsCpp is the C++ implementation of the Tars RPC framework, providing high-performance remote procedure call capabilities, IDL tooling, and utility libraries. It includes core components such as libservant for RPC implementation, wup for communication protocols, and a suite of IDL code generation tools (e.g., tars2cpp, tars2python). The framework supports asynchronous programming via the Promise pattern, coroutines, and provides implementations for HTTP and WebSocket servers.

Tokens
8K
Snippets
23
Records
56
Agent score
69%

What's inside TarsCpp

  1. Overview of TarsCpp components

    master

    TarsCpp is the C++ implementation of the Tars RPC framework. The repository is organized into several key functional areas:

    • servant: The core source code implementation of the C++ RPC framework.
    • tools: The implementation of the IDL (Interface Definition Language) tool for C++.
    • util: Basic utility libraries used by the framework.
    • examples: Sample code including quick start guides, promise-based programming examples, and pressure test programs.
    • docs / docs-en: Documentation for the framework.
  2. Overview of tarscpp RPC implementation

    master

    tarscpp is the C++ implementation of the Tars framework's RPC (Remote Procedure Call) system. It provides the core infrastructure for service communication, protocol handling, and asynchronous programming within the Tars ecosystem.

    Key components include:

    • wup: Implements the tars/wup uniform communication protocol and its codec.
    • protocol: Defines the underlying communication return codes and the interfaces used to interact with the framework's underlying services.
    • servant/libservant: The core source code implementation of the RPC framework.
    • jmem: A memory data structure component implementation based on the Tars protocol.
    • promise: An asynchronous programming implementation based on the Promise pattern.
    • script: Tooling to automate the generation of TARS service template code.
  3. Overview of tarscpp tool directory structure

    master

    The tarscpp repository contains the source code for the Tars framework C++ language IDL (Interface Definition Language) tools. The project is organized into modules responsible for lexical analysis, parsing, and code generation for various programming languages.

    Core Parsing Modules

    • tarsgrammer: Defines rules for Tars lexical and grammatical analysis.
    • tarsparse: Implements the parsing of Tars words and source code.

    IDL Code Generation Tools

    These modules implement IDL tools that generate language-specific code from .tars files:

    • tars2cpp: Generates C++ code.
    • tars2c: Generates C code.
    • tars2cs: Generates C# code.
    • tars2oc: Generates Object-C code.
    • tars2php: Generates PHP code.
    • tars2python: Generates Python code.
    • tars2node: Generates Node.js code.
    • tars2android: Generates Android code.

    Utility and Integration Tools

    • tars2case: Generates test cases for Tars servers.
    • pb2tarscpp: Generates protoc plugin source code to allow generating Tars C++ code from .proto files.
  4. Overview of tarscpp components and IDL tools

    master

    The tarscpp repository contains the source code for the Tars framework's C++ language IDL (Interface Definition Language) tools. It includes the core grammar analysis engine and a suite of code generators that convert .tars files into various programming language implementations.

    Core Engine

    • tarsgrammer: Defines the lexical and grammatical analysis rules for the Tars language.
    • tarsparse: The source implementation for parsing Tars tokens and performing grammatical analysis.

    Language Code Generators

    These tools take .tars files as input to generate language-specific code:

    • tars2cpp: Generates C++ code.
    • tars2c: Generates C code.
    • tars2cs: Generates C# code.
    • tars2oc: Generates Objective-C code.
    • tars2php: Generates PHP code.
    • tars2python: Generates Python code.
    • tars2node: Generates Node.js code.
    • tars2android: Generates Android code.

    Specialized Tools

    • tars2case: Generates test cases for Tars services.
    • pb2tarscpp: A protoc plugin implementation used to generate Tars C++ code from .proto (Protocol Buffers) files.
  5. Explore TarsCpp usage examples

    master

    The examples/ directory contains several demonstration projects designed to help developers learn different aspects of the TarsCpp framework. Depending on your goal, you can explore the following specific demos:

    • QuickStartDemo: For a fast introduction to Tars development.
    • PromiseDemo: Demonstrates asynchronous programming using the Promise pattern.
    • HttpDemo: Shows how to implement an HTTP server.
    • WebSocketServer: A WebSocketProtocol server example that includes a built-in browser testing page.
    • CoroutineDemo: Demonstrates the use of coroutines within the framework.
    • StressDemo: Provides code for performing stress tests on Tars C++ services.
    • PushDemo: Demonstrates the Tars 'Push' mode (server-to-client communication).
  6. Explore Tars Coroutine Programming Examples

    master

    The examples/CoroutineDemo directory contains sample code demonstrating how to use coroutines within the Tars framework. It is divided into two main functional areas:

    1. Client-Server Interaction (client/BServer/AServer): Demonstrates a multi-tier architecture where a client accesses BServer, and BServer uses coroutines to perform both parallel and serial requests to AServer.
    2. Custom Coroutine Implementation (testCoro/testParallelCoro): Demonstrates how to implement custom coroutine logic or extend the existing framework's coroutine classes.
  7. Explore Tars Stress Test Examples

    master

    The StressDemo project provides entry-level examples for learning how to use Tars. It consists of two primary components designed to demonstrate performance stress testing:

    • TarsStressServer: A Tars-based server application designed to be the target of performance stress tests.
    • TarsStressClient: A Tars-based client application designed to perform the stress testing against a server.

    Use these examples to understand how to implement both service providers and performance-testing clients within the Tars framework.

  8. Explore Tars Quickstart Examples

    master

    The examples/CustomDemo directory contains reference implementations for getting started with Tars. It is divided into two primary functional examples:

    • HelloServer: A basic implementation designed for rapid development onboarding and learning the core Tars service patterns.
    • ProxyServer: An example of a middleware/proxy service that acts as a proxy for the HelloServer.
  9. Configure Keepalive mode for objects

    master
    Starting from v3.0.16, keepalive mode can be configured independently for each object. Additionally, if a tars_ping response indicates there is no service or no servant available, the keepalive mode will be automatically cancelled.