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

I have a question - why are the lengths 30, 62, 126, instead of 31, 63, and 127 (and if there were a UInt2048, 255)? #29

Closed
xiaodaigh opened this issue Nov 2, 2020 · 7 comments

Comments

@xiaodaigh
Copy link
Collaborator

I have a question - why are the lengths 30, 62, 126, instead of 31, 63, and 127 (and if there were a UInt2048, 255)?
The max size length (in bytes) for any of those is just one byte (2 nibbles).
Also, since characters are only encoded in 1 or more bytes, the length could be just expressed as bytes, unless you want to use an extra nibble to store other information about the short string (which might be useful).

Originally posted by @ScottPJones in #22 (comment)

@ScottPJones
Copy link
Member

After looking more at the code, I think it's really due to a bug in the code, the code is mixing bytes and nibbles.
If the package had a hard limit of 255 bytes for ShortStrings, then it could be simplified to always use just a single byte.

@oxinabox
Copy link
Member

oxinabox commented Nov 2, 2020

If the package had a hard limit of 255 bytes for ShortStrings, then it could be simplified to always use just a single byte.

It doesn't though.
I have used it for much longer strings, and it works.
It just means using BitInteger.jl to make larger integers.

@ScottPJones
Copy link
Member

OK. For fixed size strings, generally I haven't seen greater than 255 (and that's for old legacy database fields, where they liked to have fixed size fields for everything, i.e. CHAR(255))

@ScottPJones
Copy link
Member

I'd kind of like to add ShortString255 by default - given how frequently I've seen that in database schema

@xiaodaigh
Copy link
Collaborator Author

Just a comment. I think if ppl want to use it, then I think we can create an easy to use macro as suggested before where the number at the end is not necessary. It will figure it out and homogenize it in an array for the user automatically.

ScottPJones added a commit that referenced this issue Nov 3, 2020
Fix issue #29, use bytes instead of nibbles
@ScottPJones
Copy link
Member

That's going to be one of my next steps (as I know @oxinabox wants it!)
A version of ShortString(string, maxlen) that will construct a ShortString based on maxlen,
as well as ss"foo" that will do ShortString(string, sizeof(string)).

@ScottPJones
Copy link
Member

This has now been resolved by #31

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

No branches or pull requests

3 participants