-
Notifications
You must be signed in to change notification settings - Fork 15
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
Implement customtype's (Cosmos Scalars) #2
Comments
Here's one alternate idea I had for custom types: type Coin struct {
Denom string
Amount string
amountInt cosmos.Int
amountIntLastStr string
}
func (c *Coin) GetAmountInt() (cosmos.Int, error) {
if c.Amount == c.amountIntLastStr {
return c.amountInt, nil
}
var err error
c.amountInt, err = cosmos.NewIntFromString(c.Amount)
if err != nil {
...
}
c.amountIntLastStr = c.Amount
return c.amountInt, nil
}
func (c *Coin) SetAmountInt(x cosmos.Int) {
c.amountInt = x
c.Amount = x.String()
c.amountIntLastStr = c.Amount
} Here are a few pros of this approach:
I talked about it with @fdymylja and he said it might actually be harder to handle in codegen and the panic in |
I'm thinking this alternate approach might also be more performant for marshaling with the ORM. For instance, say we have a primary key field with a custom type - in the ORM we would |
Going to follow up on some of the discussion from #45 (comment). The current proposal there I think is: type CustomType interface {
UnmarshalBytes(b []byte) error
MarshalBytes() ([]byte, error)
Size() int
Set(value protoreflect.Value)
Get() protoreflect.Value
Clear()
IsSet() bool
} One issue here is that you can't support custom types with different proto encodings. For instance, you can't have an With the |
sounds good to me, we just need to decide on the interface we want. I was thinking one interface for each proto kind. ex:
We should also decide on the skeleton of the interface implementation (what methods are needed?). Also I don't think we should use constructors or anything, all the implementation should be methods of the custom type, so to pulsar we can just pass the go import path for the custom type instead of multiple functions from the pkg of the custom type. |
One issue with defining a method like |
ValueInt64 is for reflection to check equality between private and exported field in the struct. Does mutability matter though in this case? |
But how is Value different from Marshal then? Unmarshal would make it mutable. I'm also not sure why the constructor is a problem. That can easily be derived from type name: foo/bar.Int -> foo.bar/NewIntFromString. |
Would be great to have a decision here. I'm mostly leaning towards the approach in #2 (comment) for the reasons outlined there. I also think it will be quite easy to implement. The big downside I think is that you can't do something like Other than that, I think this approach makes implementation simpler for both codegen and custom types and has the advantages of built-in caching and gradual upgradability. |
maybe the downside could be skirted a bit by codegenning some constructors? also, i forgot where we left off with this. is Frojdi still handling it? or should i take over? |
IIRC, we were awaiting on community feedback for this specific feature. |
constructors is an interesting idea, but it introduces surface area for incompatible breaing changes, because constructors generally use positional parameters
yes, that is where we left it. but either way, things should be decided mostly on technical pros/cons and their relative impact which we should be able to assess. @marbar3778 would be great to have you chime in here |
Gentle ping :) This is marked as a 1.0 blocker, so a decision here is needed to move forward with implementation. |
Thanks @elias-orijtech. Likely the whole code generator will get rewritten before 1.0 in light of cosmos/cosmos-sdk#15404 so that will likely affect this feature (as well as everything else) pretty substantially. |
would it be the same code path or potentially a different go mod to seaprate proto codegen from zero copy |
I think we'd want them to be the same codegen if we want performant message passing. The zero-copy design would be proto compatible. I'm thinking we'd be encouraging people to migrate directly to that instead of just dropping gogo for the current pulsar codegen |
lets talk about this on the team call today, would be good to have the path laid out |
cosmos_proto.scalar
proto option that appliesstring
andbytes
typesEx:
CustomType
golang interface that all golang scalar type implementations need to implement (ex.Int
), this is what we're using for gogo proto and can maybe reuse:An alternative that just deals with
string
andbytes
types could be:Depending on whether
cosmos_proto.scalar
is used on astring
orbytes
type, the corresponding interface would be used.protoreflect.Message
handlingThe text was updated successfully, but these errors were encountered: