Git Product home page Git Product logo

Comments (16)

awalterschulze avatar awalterschulze commented on June 12, 2024

You should use casttype instead of customtype.
This feature is available on the casttype branch

from protobuf.

tamird avatar tamird commented on June 12, 2024

Can casttype be made available before proto3?

from protobuf.

tamird avatar tamird commented on June 12, 2024

Also casttype doesn't work correctly - in proto2 syntax:

message RangeTreeNode {
  optional bytes left_key = 4 [(gogoproto.casttype) = "Key"];
}

In the generated code, LeftKey should be a pointer (because this thing is nullable) but it is not. Even the more explicit:

message RangeTreeNode {
  optional bytes left_key = 4 [(gogoproto.nullable) = true, (gogoproto.casttype) = "Key"];
}

yields a value type rather than a pointer.

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

casttype is not made for the bytes type.
"Changes the generated field type. It assumes that this type is castable to the original goprotobuf field type. It currently does not support byte slices, structs or enums."

If you have this usecase, maybe I should add this feature.
I was a little afraid, because I was getting sleepy and was a little worried about the side effects of just casting to a type if that type does not imply a copy.

For bytes I still recommend customtype, but I could add this feature if you think it would be useful?

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

I am thinking about merging proto3 back into master before proto3 is officially released, but I don't know yet.
golang/protobuf does not have a problem with merging their proto3 support into their master branch, so I guess I should ask myself what I am afraid of.
I'll have to run some more tests first.

I think it would be really great to launch the gofast feature on the master branch.
Why would you want this feature in master asap?

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

Ok I ran some tests. It all looks good.
I merged proto3 into master.

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

If I make casttype work for bytes as well. Their is a problem in proto/text which is very easy to fix, but their is another problem in encoding/json

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

This issue is now a duplicate of #36.

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

This is the issue with bytes as a casttype.
http://play.golang.org/p/RXlhj9_ld5

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

Do you have any ideas, maybe some annotation, that could fix this?

from protobuf.

tamird avatar tamird commented on June 12, 2024

I think in this case (our type is an alias for []byte) we should use
casttype and the Marshal/Unmarshal/Size/whatever implementations should be
generated to cast to []byte internally. What do you think?
On Jun 6, 2015 11:23 AM, "Walter Schulze" [email protected] wrote:

Do you have any ideas, maybe some annotation, that could fix this?


Reply to this email directly or view it on GitHub
#58 (comment).

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

How does that solve the json problem?

from protobuf.

tamird avatar tamird commented on June 12, 2024

http://play.golang.org/p/l9N7d3SPc0

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

Of course :)
Ok but it was not quite there

http://play.golang.org/p/Hpb0FEssL6

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

Ok the casttype branch should now support bytes as a casttype.

from protobuf.

awalterschulze avatar awalterschulze commented on June 12, 2024

Please reopen this issue it the problem still occurs.

from protobuf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.