Skip to content
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

Data driven entity generation by YAML definitions #25

Closed
axyiee opened this issue Apr 24, 2022 · 4 comments
Closed

Data driven entity generation by YAML definitions #25

axyiee opened this issue Apr 24, 2022 · 4 comments
Assignees
Labels
✨ feature request New feature or request ❗ priority: high πŸ—οΈ structuring This issue or pull request is related in how we can improve the project structure

Comments

@axyiee
Copy link
Member

axyiee commented Apr 24, 2022

Entity generation by YAML definitions

Table of contents:

Summary

We should create two code generators (one written in Kotlin and another written in Rust) which would generate entities based on fields defined in a YAML file.

Motivations and the proposed solution

As mentioned in #21, "we need to create an entity data class in Kotlin with the same contents as Rust for the rest web client, this means that we would have duplicated code". This feature would fix this problem and add more flexibility to entity changes. We could also integrate this into the command-line interface for better management of this solution.

Rust

Implementing this feature in Rust is really simple though, since we can simple use function-like procedural macrosΒΉ that read the YAML files, parse them and generate code.

Kotlin

I still haven't thought of a better way to implement this, but I know we can use Gradle tasks and square/kotlinpoetΒ² for code generation.

Examples

player.yml

---
entities:
  - name: Player
    package: org.hexalite.generation.entity
    fields:
       uuid:
         kotlin: java.util.UUID
         rust: uuid::Uuid
       hexes:
         kotlin: Int
         rust: u32
       created_at:
         kotlin: kotlinx.datetime.Instant
         rust: chrono::DateTime<chrono::Utc>

Reference

  1. Procedural macros
  2. square/kotlinpoet
  3. YAML specification

Final considerations

Suggestions are appreciated for new sections in this issue, or if you have a better idea about how to structure it, feel free to let us know about it by commenting down below. Thank you for the attention.

@axyiee axyiee added ✨ feature request New feature or request ❗ priority: high πŸ—οΈ structuring This issue or pull request is related in how we can improve the project structure labels Apr 24, 2022
@axyiee axyiee changed the title Entity generation by YAML definitions Data driven entity generation by YAML definitions Apr 24, 2022
@axyiee axyiee self-assigned this Apr 25, 2022
@axyiee axyiee closed this as completed Apr 26, 2022
@axyiee axyiee reopened this Apr 26, 2022
@axyiee
Copy link
Member Author

axyiee commented Apr 26, 2022

We should use ProtoBuf instead. It is a better alternative and it is suited for this exact use case, it would be a really better alternative.

@axyiee
Copy link
Member Author

axyiee commented Apr 26, 2022

Closed by 0b0b79e

@axyiee
Copy link
Member Author

axyiee commented Apr 28, 2022

We should use ProtoBuf instead. It is a better alternative and it is suited for this exact use case, it would be a really better alternative.

Ok, so this issue need to be reopened. There is no decent ProtoBuf compiler for Kotlin in which adds good compatibility for kotlinx.serialization and possibility to wrap classes (e.g. compatibility to UUIDs by passing an option). This issue will be closed again when we found a compiler for Kotlin, for a while we will reimplement ProtoBuf definitions in Kotlin manually.

@axyiee axyiee reopened this Apr 28, 2022
@axyiee axyiee pinned this issue Apr 28, 2022
@axyiee
Copy link
Member Author

axyiee commented May 6, 2022

We should use ProtoBuf instead. It is a better alternative and it is suited for this exact use case, it would be a really better alternative.

Ok, so this issue need to be reopened. There is no decent ProtoBuf compiler for Kotlin in which adds good compatibility for kotlinx.serialization and possibility to wrap classes (e.g. compatibility to UUIDs by passing an option). This issue will be closed again when we found a compiler for Kotlin, for a while we will reimplement ProtoBuf definitions in Kotlin manually.

It seems the official grpc-kotlin repository has support for code generation.

@axyiee axyiee closed this as completed May 6, 2022
@axyiee axyiee unpinned this issue May 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ feature request New feature or request ❗ priority: high πŸ—οΈ structuring This issue or pull request is related in how we can improve the project structure
Projects
None yet
Development

No branches or pull requests

1 participant