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

Add new functions b64encode and b4decode #50

Closed
spyzhov opened this issue Apr 22, 2022 · 8 comments
Closed

Add new functions b64encode and b4decode #50

spyzhov opened this issue Apr 22, 2022 · 8 comments
Labels
good first issue Good for newcomers

Comments

@spyzhov
Copy link
Owner

spyzhov commented Apr 22, 2022

Add new functions b64encode and b64decode that are equal to the same functions from encoding/base64

@spyzhov spyzhov added the good first issue Good for newcomers label Apr 22, 2022
@spyzhov spyzhov changed the title Add new functions base64encode and base64decode Add new functions b64encode and b4decode May 5, 2022
@spyzhov
Copy link
Owner Author

spyzhov commented May 13, 2022

Select the name for method:

  • b64encode
  • base64_encode
  • encode_base64
  • encodeB64
  • b64_encode
  • etc.

@ryzheboka
Copy link
Contributor

Hi @spyzhov
can I work on this issue? I am fairly new to Golang, so it could take some time.

@spyzhov
Copy link
Owner Author

spyzhov commented Oct 23, 2022

@ryzheboka, sure! Please create 2 new methods with names base64_encode and base64_decode.

You can implement them in the same way as function avg (source: https://github.com/spyzhov/ajson/blob/master/math.go#L363-L380).

Input and Output type should be String only.
Please cover them with tests in the math_test.go file.

@ryzheboka
Copy link
Contributor

Do I declare the methods using the following signatures?

"base64_encode": func(node *Node) (result *Node, err error) { ... }

"base64_decode": func(node *Node) (result *Node, err error) { ... }

where the each Node is a string Node? What do I do if the Node isn't a string? Or should I rather use the following signature?

"base64_encode": func(input string) (result string, err error) { ... }

@spyzhov
Copy link
Owner Author

spyzhov commented Oct 24, 2022

The first suggestion was right, it should be something like this:

		"base64_encode": func(node *Node) (result *Node, err error) {
			if node.IsString() {
				if res, err := node.GetString(); err != nil {
					return nil, err
				} else {
					var result string
					// ... implementation
					return valueNode(nil, "base64_encode", String, result), nil
				}
			}
			return valueNode(nil, "base64_encode", Null, nil), nil
		},
		"base64_decode": func(node *Node) (result *Node, err error) {

The current implementation of functions could have only 1 argument and it's applicable to any type of node.

@spyzhov
Copy link
Owner Author

spyzhov commented Nov 3, 2022

Also, please be aware that base64 can be configured with/without padding:

_, _ = base64.StdEncoding.WithPadding(base64.NoPadding).DecodeString(str)
_, _ = base64.StdEncoding.WithPadding(base64.StdPadding).DecodeString(str)

Some strings can not be decoded with/without padding.

Probably better to create 4 functions: pair of functions with and without StdPadding(=)

@ryzheboka
Copy link
Contributor

ryzheboka commented Nov 4, 2022

There seems to be a problem with https://github.com/mattn/goveralls which leads to the pipeline failure, The pipeline cannot execute go get github.com/mattn/goveralls. Here is the problem: https://app.travis-ci.com/github/spyzhov/ajson/jobs/587506014. Is it related to my PR, or is it a different problem?

@spyzhov
Copy link
Owner Author

spyzhov commented Nov 6, 2022

It's OK, when I'll press a button to run it "from my name", it will resolve this problem.

@spyzhov spyzhov closed this as completed Jan 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants