-
-
Notifications
You must be signed in to change notification settings - Fork 45
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
Support varint unpacking #52
Comments
The custom Size() method is on an instance of the type, so you'd just need to read the instance value to see what size it is and return that. Unpack Size() only seems to matter for slices, Custom unpack happens here: https://github.com/lunixbochs/struc/blob/master/fields.go#L150 e.g. https://github.com/lunixbochs/struc/blob/master/custom_float16.go#L73 could read:
|
but when |
Size is not called on Unpack. You have the data on Pack. I know exactly how varint works. |
Seems to work fine for me (note, you shouldn't use Pack to get the size, I just didn't bother looking up the thresholds to hardcode it):
|
Ohh I see.. I'll see if I can take a stab at it. Thanks a lot ! |
@abourget did you by any chance figure out how to integrate varints? |
Approximately the code I posted should already work in your own codebase without modifying struc. |
I was trying to integrate a
varint32
type (like https://github.com/Smerity/govarint/blob/master/govarint.go#L188:6 ..) by adding a type totypes.go
but I see a Custom declaration needs aSize()
which returns a constant..Do you think it would be easy to modify the lib to support a varint32 type? The size of the read is never defined beforehand.. it could be one byte, two, three, etc..
thanks!
The text was updated successfully, but these errors were encountered: