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

Use more compact encoding (like base64) instead of hex? #1

Open
unwriter opened this issue Sep 9, 2018 · 2 comments
Open

Use more compact encoding (like base64) instead of hex? #1

unwriter opened this issue Sep 9, 2018 · 2 comments

Comments

@unwriter
Copy link
Owner

unwriter commented Sep 9, 2018

The original proposal suggests hex encoding because that's the one that's most widely used at the moment.

screen shot 2018-09-09 at 3 45 01 pm

However hex format is not the most ideal when it comes to passing around because of its large size.

Here's a quick benchmark:

╔══════════╤════════════════════════════════╤══════╗
║ type     │ content                        │ size ║
╟──────────┼────────────────────────────────┼──────╢
║ Original │ Lorem ipsum dolor sit amet, co │ 212  ║
║          │ nsectetur adipiscing elit. Pro │      ║
║          │ in ut tortor blandit, placerat │      ║
║          │ ipsum non, vehicula odio. Nam  │      ║
║          │ cursus, mi sed dictum posuere, │      ║
║          │ orci nulla ultricies elit, sit │      ║
║          │ amet iaculis erat mi ut orci.  │      ║
║          │                                │      ║
╟──────────┼────────────────────────────────┼──────╢
║ Base64   │ TG9yZW0gaXBzdW0gZG9sb3Igc2l0IG │ 284  ║
║          │ FtZXQsIGNvbnNlY3RldHVyIGFkaXBp │      ║
║          │ c2NpbmcgZWxpdC4gUHJvaW4gdXQgdG │      ║
║          │ 9ydG9yIGJsYW5kaXQsIHBsYWNlcmF0 │      ║
║          │ IGlwc3VtIG5vbiwgdmVoaWN1bGEgb2 │      ║
║          │ Rpby4gTmFtIGN1cnN1cywgbWkgc2Vk │      ║
║          │ IGRpY3R1bSBwb3N1ZXJlLCBvcmNpIG │      ║
║          │ 51bGxhIHVsdHJpY2llcyBlbGl0LCBz │      ║
║          │ aXQgYW1ldCBpYWN1bGlzIGVyYXQgbW │      ║
║          │ kgdXQgb3JjaS4=                 │      ║
╟──────────┼────────────────────────────────┼──────╢
║ Hex      │ 4c6f72656d20697073756d20646f6c │ 424  ║
║          │ 6f722073697420616d65742c20636f │      ║
║          │ 6e7365637465747572206164697069 │      ║
║          │ 7363696e6720656c69742e2050726f │      ║
║          │ 696e20757420746f72746f7220626c │      ║
║          │ 616e6469742c20706c616365726174 │      ║
║          │ 20697073756d206e6f6e2c20766568 │      ║
║          │ 6963756c61206f64696f2e204e616d │      ║
║          │ 206375727375732c206d6920736564 │      ║
║          │ 2064696374756d20706f7375657265 │      ║
║          │ 2c206f726369206e756c6c6120756c │      ║
║          │ 7472696369657320656c69742c2073 │      ║
║          │ 697420616d657420696163756c6973 │      ║
║          │ 2065726174206d69207574206f7263 │      ║
║          │ 692e                           │      ║
╚══════════╧════════════════════════════════╧══════╝

The hex format in this case increases the original message's size 2x.

Also shown on the table, the base64 encoding also increases the size but not as much as hex. Plus it's also a widely used format (although not as much as hex format due to its lack of readability), so base64 might be a better choice.

Some people have brought up other types of encoding schemes as well. Will need to consider if they're better than base64.

@unwriter
Copy link
Owner Author

One concern against base64 is that it includes certain special characters like /, +, and =, each of which is already being used for special purposes in the conventional URI scheme (/ being used as a path identifier for example).

This issue could be ignored if the standard enforces a very strict and distinct grammar but will need to consider both pros and cons first.

@ghost
Copy link

ghost commented May 10, 2019

There's browser safe base64. This is a good idea given that QRs are significantly smaller this way.

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

1 participant