0.0.1 • Published 2 years ago

protobuf-to-data-classes v0.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

proto-to-data-classes

A simple codegen tool for convert protobuf to corresponding data classes in some programming language to use with some JSON libraries (Gson, Codable).

Table of Contents

Usage

Install

npm install protobuf-to-data-classes

or

yarn add protobuf-to-data-classes

Coding

A code example:

import { convertProtobufToDataClasses, DataClassType } from 'protobuf-to-data-classes';

const content = `
syntax = 'proto3';
message Foo {
  string bar = 1;
}
`;

generatedCode = convertProtobufToDataClasses(content, DataClassType.KotlinGson);
console.log(generatedCode);

The resulted code:

import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

data class Foo(
    @Expose
    @SerializedName("bar")
    val bar: String?,
)

API

`convertProtobufToDataClasses(protobuf: string, dataClassType: DataClassType): string

Generate corresponding data classes for the given protobuf content.

TODO

  • Support more options for data classes.
  • Refactor code because the current code base is not good :].
  • Create a simple web app.