-
Notifications
You must be signed in to change notification settings - Fork 193
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
Struct fields numeric labels #160
base: master
Are you sure you want to change the base?
Conversation
Also, I have a question about decision according to this thread. If it is necessary to declare label types also as |
Hey, thanks for the PR. This is going to take me a day or two to review, since it's a substantial change. Just for my own edification, could you point me to a place where this would be used 'in the wild?' |
Also, can I suggest the following for syntax: type Foo struct {
Bar string `msg:0x03"
} We should be able to disambiguate string field names from integer field names simply by the presence of quotes. I'd also make unsigned integers the default, and then make |
gen/spec.go
Outdated
case string: | ||
t = msgp.StrType | ||
default: | ||
panic(fmt.Errorf("field %q has unknown tag type %T", f.FieldName, f.FieldTag)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't panic here; print an error and exit. Same goes for field label parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are already few cases when generator panics. For example, here. So is it really necessary to print error and do some of os.Exit(1)
?
Hey @philhofer, Yeah, I agree with syntax you suggested. But my question above is still actual – should we take care on strong typed labels, like About usage 'in the wild' I do not clearly understand your question. If this is about concrete use case – I need this to implement some binary protocol to integrate with. It is very much like, for example, this one. |
Great; I was just curious about who was serializing things this way already.
Practically speaking, I'd imagine most things will end up being encoded as a 127-bit fixint anyway (and most everything else in one of the fixed-width unsigned types), so I don't think this is necessary, but I'm happy to be convinced otherwise. |
Hello @philhofer! Just returned to complete this feature. Please look what I have found about the use of field tag values without quotes: play.golang.org. That is, it is not possible to distinguish numeric label vs. string simply by presence of quoutes without breaking other tags cause it is violates "conventional format". type Foo struct {
Bar string `msg:"0x03,uint"`
} |
gen/spec.go
Outdated
case string: | ||
t = msgp.StrType | ||
default: | ||
panic(fmt.Sprintf( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will duplicate my previous comment to not loose it:
There are already few cases when generator panics. For example, here. So is it really necessary to print error and do some of os.Exit(1)?
If it is, I could move logging logic from parse
package to separate package, e.g. internal/log
, and reuse functions like warnf
,warnln
etc., and also refactor fatalf
to print log message and do os.Exit(1)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds great.
@philhofer ping 👀 |
parse/getast.go
Outdated
var err error | ||
switch tags[1] { | ||
case "uint": | ||
str, base := numeric(tags[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strconv.ParseInt(tags[0], 0, 64)
will infer hex or octal based on the prefix; no need to do that yourself.
@philhofer thanks! Applied your comments, and moved logging logic to the |
Hello @philhofer! Is it able to merge this? ) It becomes little bit uncomfortable to live with fork 😞 |
Ping @philhofer =) |
I have also refactored code generation for maps – now you could marshal/unmarshal not only |
@philhofer could you stop ignoring this? =) |
FYI @gobwas, the tests failed (I'm not associated with this project, but just thought you might like to know):
|
@pwaller thanks =) Fixed. |
@philhofer may be today? 🤣 |
* Add (*Reader).CopyNext(w) (int64, error) It is useful to be able to efficiently copy objects without decoding them. My use case is filtering when I already know the indices of the objects I want to keep, and for rewriting a dictionary of objects as a column of objects. * Remove ReadNext * Add opportunistic optimization with m.R.Next * Remove unused ReadNextError * Remove commented code * small fixup - only call (*Reader).Next() when we're sure it won't realloc its buffer - promote io.ErrUnexpectedEOF to msgp.ErrShortBytes
@philhofer Wondering if this PR will still be merged? |
Hello!
This pull request is about this issue.
I think it could be useful. Some integration protocols use scheme, when map keys are numerical (
int
oruint
), for example, to reduce network usage and other performance needs.Regards,
Sergey.
This change is