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

Added Base8 Implementation #26

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Added Base8 Implementation #26

wants to merge 5 commits into from

Conversation

gowthamgts
Copy link
Contributor

No description provided.

@gowthamgts gowthamgts changed the title Fixing go lint warnings Added Base8 Implementation Nov 25, 2018
@gowthamgts
Copy link
Contributor Author

Should creating a base8_test file would be the best case to increase coverage?

@gowthamgts
Copy link
Contributor Author

ping @Stebalien

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to define what base8 means for us before we implement it. This implementation expects that each group of 3 digits maps to a single byte. However, 0o777 (7777 in multibase) is 511 (doesn't fit in a single byte).

The simplest mapping I know of is 8 octal digits onto 3 bytes. However, if we go with that, we'll probably want to accept octal strings that aren't a multiple of 8 (automatically padding out to a multiple of 8).

Regardless, you'll need to submit a PR to https://github.com/multiformats/multibase/ describing the encoding (unless you can fine some existing RFC).


(I'd also kind of like to know why you need octal before we go through the process of defining and implementing it)

@@ -81,8 +83,9 @@ func TestDecode(t *testing.T) {
func TestRoundTrip(t *testing.T) {
buf := make([]byte, 17)
rand.Read(buf)
fmt.Println(buf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best to avoid printf in tests. If you want to log this, please use t.Log.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was by a mistake. Removed now.

base8.go Outdated

// decodeOctalString takes an octal string and gives byte array of decimals
func decodeOctalString(s string) ([]byte, error) {
data := make([]byte, len(s)/3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd move this after the length check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@gowthamgts
Copy link
Contributor Author

I've fixed the recommended changes in code.

(I'd also kind of like to know why you need octal before we go through the process of defining and implementing it)

I was reading the code and found out base8 was missing and I had some time so. 😕

@Stebalien
Copy link
Member

I was reading the code and found out base8 was missing and I had some time so.

Fair enough. That's also why we have base 2... But we'll still need some spec first.

@gowthamgts
Copy link
Contributor Author

Totally understandable. Thanks for your time.

@Stebalien Stebalien added the status/blocked Unable to be worked further until needs are met label Nov 28, 2018
@gowthamgts
Copy link
Contributor Author

@Stebalien: Can I implement base2 encoding in reference with RFCs?

@Stebalien
Copy link
Member

Go ahead.

* upstream/master:
  ci: standardize
  test implementation against test-vectors
  gx: ignore tests when publishing as well
  add the spec as a submodule
@creationix
Copy link

Regarding spec for base 8, I gave this some thought.

For bases that evenly break bytes into characters, pad to full bytes, this is base 2 (8 chars), base 4 (4 chars), and base 16 (2 chars). It makes sense for these to treat as bitstreams and pad out to whole bytes.

But for other power of two bases that don't evenly fit into a byte, use optional padding at the end. Examples are base64 (3 bytes = 4 chars), and base32 (5 bytes = 8 chars).

Base 8 (3 bytes = 8 chars) could fit in this style encoding.

Another option and the one JS currently uses is to convert to a large number and make leading zeroes represent null bytes similar to base 10 and base 58.

@creationix
Copy link

I wrote a base-8 codec that works similar to base-32 and base-64 where you give it an alphabet and an optional padding character. https://github.com/filecoin-project/lua-filecoin/blob/master/base-8.lua

For example base8 with '01234567=' as alphabet using same style as base-32 and base-64:

  • Decentralize everything!! ->
    72106254331267164344605543227514510062566312711713506415133463441102=====
  • hello world - 7320625543306744035667562330620==

But if I instead use base-x (which is what the JS implementation currently does), it looks closer to the current test vectors, but different leading zeroes:

  • Decentralize everything!! -> 71043126154533472162302661513646244031273145344745643206455631620441
  • hello world - 764145330661571007355734466144

@Stebalien
Copy link
Member

Stebalien commented Jul 24, 2019

@creationix I'm fine with either but I'd like to go with what's commonly used in the community. Have you found any other users of base8?

@creationix
Copy link

I've not seen any others. I don't know if there is a common encoding for this. Logically, the same style as base-64 and base-32 makes the most sense.

@Stebalien
Copy link
Member

So, the real question is, should we even bother? A viable option is to just drop base8.

@creationix
Copy link

Personally I see base-2 and base-8 both as unneeded. Is there any use case where they are the correct solution? Base-16 works everywhere and encodes much shorter and easier than them.

My recommendation is to either drop them to reduce the maintenance overhead for implementations or to go with the logical encoding as I've suggested if we must keep base-8.

@Stebalien
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/blocked Unable to be worked further until needs are met
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants