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

Add support for extending the class generated for a given Message #253

Open
rbarrois opened this issue Jun 29, 2021 · 0 comments
Open

Add support for extending the class generated for a given Message #253

rbarrois opened this issue Jun 29, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@rbarrois
Copy link

Currently, the library provides some automated conversion between the Well-known Google types (eg Timestamp <=> datetime).

Projects may wish to use similar conversion rules between some protobuf messages and internal types in their code (for instance, UUID or Decimal).
Would it be possible to add some configuration options to the plugin so that the user may configure their own field converters, or at least inject methods and properties to the auto-generated dataclasses?

Ideally, I'd like to be able to get:

@dataclass
class Transaction(betterproto.Message):
  id: foo.UUID
  amount: foo.Decimal

Another option would be to have:

@dataclass
class Decimal(betterproto.Message):
  coefficient: int
  exponent: int

  @property
  def decimal(self):
    return foo.convert_from_message(self)

  @decimal.setter
  def decimal(self, value):
    return foo.convert_to_message(self, value)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants