Skip to content

[GenerateCode] .proto supports multiple file generation #442

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
iohao opened this issue Mar 22, 2025 · 0 comments
Closed

[GenerateCode] .proto supports multiple file generation #442

iohao opened this issue Mar 22, 2025 · 0 comments
Assignees
Labels
enhancement;功能增强 Function enhancement;功能增强

Comments

@iohao
Copy link
Owner

iohao commented Mar 22, 2025

Java

LoginVerifyMessage and BulletMessage are stored in different directories through ProtoFileMerge.

example code

public interface SdkProtoFile {
    String fileName = "common.proto";
    String filePackage = "pb.common";

    String fileName2 = "common2.proto";
    String filePackage2 = "pb.common2";
}

@ToString
@ProtobufClass
@FieldDefaults(level = AccessLevel.PUBLIC)
@ProtoFileMerge(fileName = SdkProtoFile.fileName, filePackage = SdkProtoFile.filePackage)
public final class LoginVerifyMessage {
    /** jwt */
    String jwt;
}

@ToString
@ProtobufClass
@FieldDefaults(level = AccessLevel.PUBLIC)
@ProtoFileMerge(fileName = SdkProtoFile.fileName2, filePackage = SdkProtoFile.filePackage2)
public final class BulletMessage {
    /** id */
    int bulletId;
    /** bullet name */
    String name;
}

Java action

@ActionController(SdkCmd.cmd)
public final class SdkAction {
    @ActionMethod(SdkCmd.loginVerify)
    public UserMessage loginVerify(LoginVerifyMessage verifyMessage, FlowContext flowContext) {
       ...
    }
    
    @ActionMethod(SdkCmd.bulletMessage)
    public BulletMessage bulletMessage(BulletMessage message) {
        ...
    }
}

.proto

The generated content of .proto is as follows

.
├── common.proto
└── common2.proto

common.proto

syntax = "proto3";
package pb.common;

// LoginVerify
message LoginVerifyMessage {
  // jwt
  string jwt = 1;
}

common2.proto

syntax = "proto3";
package pb.common2;

// Bullet
message BulletMessage {
  // id
  int32 bullet_id = 1;
  // bullet name
  string name = 2;
}

GenerateCode

The generated C# code snippet is as follows

public static class SdkAction
{
    ...
        
    public static RequestCommand OfBulletMessage(Pb.Common2.BulletMessage message, CallbackDelegate callback)
    {
        ...
    }

    public static RequestCommand OfLoginVerify(Pb.Common.LoginVerifyMessage verifyMessage, CallbackDelegate callback)
    {
        ...
    }
}

The generated TypeScript code snippet is as follows

import * as common2_pb from "../common2_pb";
import * as common_pb from "../common_pb";
....

export class SdkAction {
    ...
    
    static ofBulletMessage(message: common2_pb.BulletMessage, callback: (result: ResponseResult) => void): RequestCommand {
        ...
    }

    static ofLoginVerify(verifyMessage: common_pb.LoginVerifyMessage, callback: (result: ResponseResult) => void): RequestCommand {
        ...
    }
}

 

@iohao iohao added enhancement;功能增强 Function enhancement;功能增强 future;将要提供 Features to be provided in the upcoming versions;近期版本将要提供的功能 labels Mar 22, 2025
@iohao iohao self-assigned this Mar 24, 2025
@iohao iohao added enhancement;功能增强 Function enhancement;功能增强 and removed enhancement;功能增强 Function enhancement;功能增强 future;将要提供 Features to be provided in the upcoming versions;近期版本将要提供的功能 labels May 9, 2025
@iohao iohao closed this as completed May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement;功能增强 Function enhancement;功能增强
Projects
None yet
Development

No branches or pull requests

1 participant