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

Strings Have A 2 (Or More) Byte Type Overhead #7

Closed
SolarScuffle-Bot opened this issue Jul 19, 2023 · 3 comments
Closed

Strings Have A 2 (Or More) Byte Type Overhead #7

SolarScuffle-Bot opened this issue Jul 19, 2023 · 3 comments

Comments

@SolarScuffle-Bot
Copy link

SolarScuffle-Bot commented Jul 19, 2023

image

https://data-oriented-house.github.io/Squash/docs/binary#strings

I realize the code is a simple #string + 2, though the initial TYPE_OVERHEAD variable made it seem like every type only has 1 byte of overhead. Also much like with remote functions, the number of size bytes changes when the value reaches 0x80 (128 characters) because it uses a Variable Length Quantity (VLQ) encoding scheme

@SolarScuffle-Bot SolarScuffle-Bot changed the title Strings Have A 2 Byte Type Overhead Strings Have A 2 (Or More) Byte Type Overhead Jul 19, 2023
@Pyseph
Copy link
Owner

Pyseph commented Jul 19, 2023

If I'm understanding correctly, the#String + 2 should instead be #String + math.ceil(#String / 128) (type overhead being added afterwards; I'll update GetDataByteSize to append the type overhead also) - would this be the intended behavior? I'll take a further look tomorrow.

@SolarScuffle-Bot
Copy link
Author

I believe the calculation would be math.ceil(math.log(#string + 1, 128)).

@Pyseph
Copy link
Owner

Pyseph commented Jul 20, 2023

The above calculation wouldn't work when #string == 0, as the output would be 0; which I assume isn't the correct behavior. I've implemented the following function:

local function GetVLQSize(InitialSize: number, Length: number)
	return math.max(math.ceil(math.log(Length + InitialSize, 128)), InitialSize)
end

@Pyseph Pyseph closed this as completed in 83eba7a Jul 20, 2023
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

2 participants