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 ParseFromString for compatibility #323

Open
Laurens-T opened this issue Jan 20, 2022 · 2 comments · May be fixed by #336
Open

Add ParseFromString for compatibility #323

Laurens-T opened this issue Jan 20, 2022 · 2 comments · May be fixed by #336
Labels
good first issue Good for newcomers

Comments

@Laurens-T
Copy link

Laurens-T commented Jan 20, 2022

I currently use the standard protobuf method ParseFromString quite a bit, but noticed that the generated betterproto dataclasses don't have this method, but they do have SerializeToString for compatibility.

Is there a reason ParseFromString isn't added?

I currently have a reasonable amount of repositories that use ParseFromString, which would require me to refactor quite a bit extra at once without this method.

For clarity, here's an example of what some of the code looks like right now:

syntax = "proto3";

package hello;

message Hello {
  string message = 1;
}
from hello_pb2 import Hello

hello = Hello()
hello.ParseFromString(bytes(Hello))  # dummy example

but it would be nice if I could do the following with betterproto:

from dataclasses import dataclass
import betterproto


@dataclass
class Hello(betterproto.Message):
    """Greeting represents a message you can tell a user."""

    message: str = betterproto.string_field(1)

hello = Hello(message='betterproto')
hello.ParseFromString(bytes(Hello))  # dummy example
@Gobot1234 Gobot1234 added the good first issue Good for newcomers label Feb 7, 2022
@Gobot1234
Copy link
Collaborator

There isn't any reason I know of

@simon-saliba
Copy link

This is a problem I've encountered before and I believe that the compatibility with the standard protobuf implementation has merit to being supported.
I opened a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants