-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
251 additions
and
36 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
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
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
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,23 @@ | ||
package dsd | ||
|
||
import ( | ||
"encoding/hex" | ||
"strings" | ||
) | ||
|
||
// safeFirst16Bytes return the first 16 bytes of the given data in safe form. | ||
func safeFirst16Bytes(data []byte) string { | ||
if len(data) == 0 { | ||
return "<empty>" | ||
} | ||
|
||
return strings.TrimPrefix( | ||
strings.SplitN(hex.Dump(data), "\n", 2)[0], | ||
"00000000 ", | ||
) | ||
} | ||
|
||
// safeFirst16Chars return the first 16 characters of the given data in safe form. | ||
func safeFirst16Chars(s string) string { | ||
return safeFirst16Bytes([]byte(s)) | ||
} |
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,29 @@ | ||
package dsd | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestSafeFirst16(t *testing.T) { | ||
t.Parallel() | ||
|
||
assert.Equal(t, | ||
"47 6f 20 69 73 20 61 6e 20 6f 70 65 6e 20 73 6f |Go is an open so|", | ||
safeFirst16Bytes([]byte("Go is an open source programming language.")), | ||
) | ||
assert.Equal(t, | ||
"47 6f 20 69 73 20 61 6e 20 6f 70 65 6e 20 73 6f |Go is an open so|", | ||
safeFirst16Chars("Go is an open source programming language."), | ||
) | ||
|
||
assert.Equal(t, | ||
"<empty>", | ||
safeFirst16Bytes(nil), | ||
) | ||
assert.Equal(t, | ||
"<empty>", | ||
safeFirst16Chars(""), | ||
) | ||
} |
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
Oops, something went wrong.