-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: Migrate to Meta Processors (#7)
* feat: add JSON support for byte content * fix: improve JSON validation * feat: init meta processors * refactor!: remove array & add data support * refactor!: remove array support * refactor!: remove array support * test: add required options test * refactor: update error handling * refactor: update error handling * refactor!: remove array support * refactor: update error handling * refactor: update error handling * refactor: update error handling * refactor!: remove retain keys option * refactor!: remove array support * refactor: update error handling * refactor: standardize style * refactor!: update process lib
- Loading branch information
Showing
53 changed files
with
2,334 additions
and
1,379 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package base64 | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
) | ||
|
||
// Decode is a convenience wrapper for base64 decoding bytes. | ||
func Decode(b []byte) ([]byte, error) { | ||
decode := make([]byte, base64.StdEncoding.DecodedLen(len(b))) | ||
n, err := base64.StdEncoding.Decode(decode, b) | ||
if err != nil { | ||
return nil, fmt.Errorf("decode: %v", err) | ||
} | ||
|
||
return decode[:n], nil | ||
} | ||
|
||
// Encode is a convenience wrapper for base64 encoding bytes. | ||
func Encode(b []byte) []byte { | ||
encode := make([]byte, base64.StdEncoding.EncodedLen(len(b))) | ||
base64.StdEncoding.Encode(encode, b) | ||
|
||
return encode | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package base64 | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
var decodeTests = []struct { | ||
name string | ||
test []byte | ||
expected []byte | ||
}{ | ||
{ | ||
name: "foo", | ||
test: []byte(`Zm9v`), | ||
expected: []byte(`foo`), | ||
}, | ||
{ | ||
name: "zlib", | ||
test: []byte(`eJwFwCENAAAAgLC22Pd3LAYCggFF`), | ||
expected: []byte{120, 156, 5, 192, 33, 13, 0, 0, 0, 128, 176, 182, 216, 247, 119, 44, 6, 2, 130, 1, 69}, | ||
}, | ||
} | ||
|
||
func TestBase64Decode(t *testing.T) { | ||
for _, test := range decodeTests { | ||
result, err := Decode(test.test) | ||
if err != nil { | ||
t.Logf("got error %v", err) | ||
t.Fail() | ||
return | ||
} | ||
|
||
if c := bytes.Compare(result, test.expected); c != 0 { | ||
t.Logf("expected %s, got %s", test.expected, result) | ||
t.Fail() | ||
} | ||
} | ||
} | ||
|
||
func benchmarkBase64Decode(b *testing.B, test []byte) { | ||
for i := 0; i < b.N; i++ { | ||
Decode(test) | ||
} | ||
} | ||
|
||
func BenchmarkBase64Decode(b *testing.B) { | ||
for _, test := range encodeTests { | ||
b.Run(string(test.name), | ||
func(b *testing.B) { | ||
benchmarkBase64Decode(b, test.test) | ||
}, | ||
) | ||
} | ||
} | ||
|
||
var encodeTests = []struct { | ||
name string | ||
test []byte | ||
expected []byte | ||
}{ | ||
{ | ||
name: "foo", | ||
test: []byte(`foo`), | ||
expected: []byte(`Zm9v`), | ||
}, | ||
{ | ||
name: "zlib", | ||
test: []byte{120, 156, 5, 192, 33, 13, 0, 0, 0, 128, 176, 182, 216, 247, 119, 44, 6, 2, 130, 1, 69}, | ||
expected: []byte(`eJwFwCENAAAAgLC22Pd3LAYCggFF`), | ||
}, | ||
} | ||
|
||
func TestBase64Encode(t *testing.T) { | ||
for _, test := range encodeTests { | ||
result := Encode(test.test) | ||
|
||
if c := bytes.Compare(result, test.expected); c != 0 { | ||
t.Logf("expected %s, got %s", test.expected, result) | ||
t.Fail() | ||
} | ||
} | ||
} | ||
|
||
func benchmarkBase64Encode(b *testing.B, test []byte) { | ||
for i := 0; i < b.N; i++ { | ||
Encode(test) | ||
} | ||
} | ||
|
||
func BenchmarkBase64Encode(b *testing.B) { | ||
for _, test := range encodeTests { | ||
b.Run(string(test.name), | ||
func(b *testing.B) { | ||
benchmarkBase64Encode(b, test.test) | ||
}, | ||
) | ||
} | ||
} |
Oops, something went wrong.