diff options
author | Emiliano Ciavatta | 2020-04-25 17:25:55 +0000 |
---|---|---|
committer | Emiliano Ciavatta | 2020-04-25 17:26:05 +0000 |
commit | 8bd21ad9873690c52485e3581a8108c6f351e3a6 (patch) | |
tree | 3998d401e3963f05b15a68a47c84beaeb3c466fa /utils.go | |
parent | 4f82402b345af658eee6485801426857e16f49f8 (diff) |
Add connection_streams_controller
Diffstat (limited to 'utils.go')
-rw-r--r-- | utils.go | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -2,6 +2,8 @@ package main import ( "crypto/sha256" + "encoding/base32" + "encoding/base64" "encoding/binary" "encoding/hex" "fmt" @@ -77,3 +79,30 @@ func FileSize(filename string) int64 { func byID(id RowID) OrderedDocument { return OrderedDocument{{"_id", id}} } + +func DecodeBytes(buffer []byte, format string) string { + switch format { + case "hex": + return hex.EncodeToString(buffer) + case "hexdump": + return hex.Dump(buffer) + case "base32": + return base32.StdEncoding.EncodeToString(buffer) + case "base64": + return base64.StdEncoding.EncodeToString(buffer) + case "ascii": + str := fmt.Sprintf("%+q", buffer) + return str[1 : len(str)-1] + case "binary": + str := fmt.Sprintf("%b", buffer) + return str[1 : len(str)-1] + case "decimal": + str := fmt.Sprintf("%d", buffer) + return str[1 : len(str)-1] + case "octal": + str := fmt.Sprintf("%o", buffer) + return str[1 : len(str)-1] + default: + return string(buffer) + } +} |