Golang encoding/base32.Encoding.Decode function example

package encoding/base32

Decode decodes src(2nd parameter) using the encoding enc. It writes at most DecodedLen(len(src)) bytes to dst(1st parameter) and returns the number of bytes written. If src contains invalid base32 data, it will return the number of bytes successfully written and CorruptInputError. New line characters (\r and \n) are ignored.

Golang encoding/base32.Encoding.Decode function usage example

 func packBase32(s string) []byte {
 b32len := base32.HexEncoding.DecodedLen(len(s))
 buf := make([]byte, b32len)
 n, _ := base32.HexEncoding.Decode(buf, []byte(s))  // <----- Decode function
 buf = buf[:n]
 return buf
 }

References :

http://golang.org/pkg/encoding/base32/#Encoding.Decode

https://github.com/skynetservices/skydns/blob/master/nsec3.go

Advertisement