Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Alibaba MNN FlatBuffers gRPC Gen CPP

From Leeroopedia


Knowledge Sources
Domains Serialization, RPC
Last Updated 2026-02-10 12:00 GMT

Overview

C++ gRPC stub generator that emits client and server service classes using FlatBuffers as the wire format.

Description

cpp_generator.cc implements the C++ gRPC stub generation logic. It generates .grpc.fb.h and .grpc.fb.cc files containing service base classes, client stubs, and server interfaces that use flatbuffers::grpc::Message<T> for request and response types instead of Protocol Buffers messages. The generator handles unary RPCs, client streaming, server streaming, and bidirectional streaming method signatures.

Usage

Vendored dependency used internally by MNN for model serialization. Not directly imported by end users.

Code Reference

Source Location

  • Repository: Alibaba_MNN
  • File: 3rd_party/flatbuffers/grpc/src/compiler/cpp_generator.cc
  • Lines: 1-1780

Signature

namespace grpc_cpp_generator {
  grpc::string GetHeaderPrologue(grpc_generator::File *file,
                                  const Parameters &params);
  grpc::string GetHeaderServices(grpc_generator::File *file,
                                  const Parameters &params);
  grpc::string GetSourceServices(grpc_generator::File *file,
                                  const Parameters &params);
}

Import

#include "src/compiler/cpp_generator.h"

I/O Contract

Input Output
grpc_generator::File with service and method descriptors C++ header with service stub classes (.grpc.fb.h)
grpc_generator::File with service and method descriptors C++ source with service implementations (.grpc.fb.cc)

Usage Examples

// Generated service usage:
class MonsterStorageServiceImpl final
    : public MonsterStorage::Service {
    grpc::Status Store(grpc::ServerContext *ctx,
        const flatbuffers::grpc::Message<Monster> *request,
        flatbuffers::grpc::Message<Stat> *response) override {
        // Handle request
        return grpc::Status::OK;
    }
};

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment