Skip to content

Enumeratum support#20

Merged
cb372 merged 2 commits intomasterfrom
enumeratum-support
Dec 11, 2019
Merged

Enumeratum support#20
cb372 merged 2 commits intomasterfrom
enumeratum-support

Conversation

@cb372
Copy link
Copy Markdown
Member

@cb372 cb372 commented Dec 11, 2019

Add support for reading and writing enumeratum IntEnums. These are enumerations whose elements have both a name and an integer value.

This means that in Mu we'll be able to preserve the integer values of protobuf enums. Given a .proto file:

enum Colour {
  BLUE = 0;
  RED = 5;
}

, instead of generating:

sealed trait Colour
object Colour {
  case object BLUE extends Colour
  case object RED extends Colour
}

like we currently do, we can instead encode it as:

sealed trait Colour(val value: Int) extends IntEnumEntry
object Colour extends IntEnum[Colour] {
  case object BLUE extends Colour(0)
  case object RED extends Colour(5)

  val values = findValues
}

This means PBDirect can encode/decode the enum using the correct integer values.

Also if lloydmeta/enumeratum#263 gets merged and released, we will be able to handle enums with aliases.

These enums have integer values, so we will be able to use them in Mu to
encode protobuf enums including their numerical values.
Copy link
Copy Markdown
Member

@juanpedromoreno juanpedromoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks @cb372

cb372 added a commit to higherkindness/skeuomorph that referenced this pull request Dec 11, 2019
See 47degrees/pbdirect#20

Because it is still a plain old sealed abstract class + case object
hierarchy, this change will not affect Avro serialization using avro4s
(confirmed with manual testing).

Note: This change assumes that enumeratum is on Mu's classpath, which is
not yet true. PR on the way to add it as a dependency.
@cb372 cb372 merged commit b61489c into master Dec 11, 2019
@cb372 cb372 deleted the enumeratum-support branch December 11, 2019 17:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants