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 Java

From Leeroopedia


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

Overview

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

Description

java_generator.cc implements the Java gRPC stub generation logic. It generates Java source files containing abstract service base classes, client stubs, and method descriptors that use FlatBuffers for message serialization. The generated code integrates with the io.grpc Java framework and uses the FlatBuffers Java runtime for marshaling. It supports unary, client streaming, server streaming, and bidirectional streaming RPC patterns.

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/java_generator.cc
  • Lines: 1-1138

Signature

namespace grpc_java_generator {
  grpc::string GetServices(const grpc_generator::File *file);
  grpc::string GetHeader(const grpc_generator::File *file,
                          const Parameters &params);
}

Import

#include "src/compiler/java_generator.h"

I/O Contract

Input Output
grpc_generator::File with service and method descriptors Java source file with gRPC service stubs (*Grpc.java)

Usage Examples

// Generated Java service usage (shown as Java code):
// public class MonsterStorageGrpc {
//     public static abstract class MonsterStorageImplBase
//         implements io.grpc.BindableService {
//         public void store(Monster request,
//             io.grpc.stub.StreamObserver<Stat> responseObserver) { }
//     }
// }

Related Pages

Page Connections

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