How to use the MaxEncodedLen function in Go
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.
Prototype
Parameters and return type
The MaxEncodedLen() function accepts the number of source bytes as type int and returns the maximum encoded length as type int.
Example
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
Copyright ©2026 Educative, Inc. All rights reserved