Skip to content

A small and simple .proto file generator. Generates a protobuf schema from the given kotlin classes.

License

Notifications You must be signed in to change notification settings

smyrgeorge/protogen4k

Folders and files

NameName
Last commit message
Last commit date

Latest commit

6fce2d2 · Aug 22, 2024

History

7 Commits
Aug 22, 2024
May 15, 2024
May 15, 2024
Aug 22, 2024
Aug 22, 2024
May 15, 2024
May 15, 2024
Aug 22, 2024
May 15, 2024
May 15, 2024
May 15, 2024

Repository files navigation

protogen4k

Build Maven Central GitHub License GitHub commit activity GitHub issues

A small and simple .proto file generator. Generates a protobuf schema from the given kotlin classes.

Usage

<dependency>
    <groupId>io.github.smyrgeorge</groupId>
    <artifactId>protogen4k</artifactId>
    <version>x.y.z</version>
</dependency>

or using gradle:

implementation("io.github.smyrgeorge:protogen4k:x.y.z")

Examples

Let's see an example.

package io.github.smyrgeorge.datasuite.converter.protobuf.examples

import io.github.smyrgeorge.datasuite.converter.protobuf.KotlinClassToProtobuf
import io.github.smyrgeorge.datasuite.converter.protobuf.annotation.ProtoFile

class Main

@ProtoFile(name = "a_class.proto", schema = "schema1")
data class AClass(
    val a: String,
    val b: List<AnEnum>
) {
    enum class AnEnum {
        A, B
    }
}

fun main(args: Array<String>) {
    KotlinClassToProtobuf.generate(
        topicPrefix = "sample",
        workDirectory = "examples/src/main/proto",
        classes = listOf(AClass::class),
        protoPackage = "io.github.smyrgeorge.datasuite.proto"
    )
}

The above kotlin code will generate 2 .proto files.

// file: a_class.proto
syntax = "proto3";

package io.github.smyrgeorge.datasuite.proto;

option java_package = "io.github.smyrgeorge.datasuite.proto";
option java_outer_classname = "AClassProto";

import "default.proto";

message AClass {
  string a = 1;
  repeated AClassAnEnum.Enum b = 2;
}
// file: default.proto
syntax = "proto3";

package io.github.smyrgeorge.datasuite.proto;

option java_package = "io.github.smyrgeorge.datasuite.proto";
option java_outer_classname = "DefaultProto";

message AClassAnEnum {
  enum Enum {
    PROTO_EMPTY = 0;
    A = 1;
    B = 2;
  }
}

About

A small and simple .proto file generator. Generates a protobuf schema from the given kotlin classes.

Topics

Resources

License

Stars

Watchers

Forks

Languages