Golang encoding/base32.Encoding.DecodedLen function example

package encoding/base32

DecodedLen returns the maximum length in bytes of the decoded data corresponding to n bytes of base32-encoded data.

Golang encoding/base32.Encoding.DecodedLen function usage example

 func packBase32(s []byte) ([]byte, error) {
 b32len := base32.HexEncoding.DecodedLen(len(s)) // <---- DecodedLen()
 buf := make([]byte, b32len)
 n, err := base32.HexEncoding.Decode(buf, []byte(s))
 if err != nil {
 return nil, err
 }
 buf = buf[:n]
 return buf, nil
 }

References :

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

https://github.com/miekg/dns/blob/master/msg.go

Advertisement