The MaxEncodedLen()
function in Go reports the maximum encoding length of a given number of bytes.
The program needs to include the encoding/ascii85
module to use the MaxEncodedLen()
function.
The MaxEncodedLen()
function accepts the number of source bytes as type int
and returns the maximum encoded length as type int
.
The following code demonstrates how to use the MaxEncodedLen()
function:
package mainimport ("fmt""encoding/ascii85")func main() {// calculate encoding len of a source of length 5x := ascii85.MaxEncodedLen(5)// display maximum encoded lengthfmt.Println(x)}
The above program takes the length of a byte source, which is 5, and calculates its maximum encoded length, which is 10.
Free Resources