Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

@unwriter

Description

@unwriter

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions