func Decode(dst, src []byte, flush bool) (ndst, nsrc int, err error)
is a method defined in the encoding/ascii85
package in Golang that decodes ascii-85 encoded source bytes of an array to a destination bytes array.
Decode()
returns the number of bytes successfully written in the destination array, the number of bytes consumed from the source array, and a CorruptInputError
.
src
: An ascii-85 encoded source byte
array that will be decoded.
dst
: Destination byte
to the array to which the decoded output will be written.
flush
: When true
, Decode()
processes the src
array completely. When false
, it waits for the completion of another 32-bit block.
ndst
: Number of bytes written to dst
. Type is int
.
nsrc
: Number of bytes consumed from src
. Type is int
.
package mainimport ("encoding/ascii85""fmt")func main() {src1 := []byte("Ascii85 encoding in Golang.")dst1 := make([]byte, ascii85.MaxEncodedLen(len(src1)))var bytes_written int = ascii85.Encode(dst1, src1)fmt.Printf("Encoded array: %s\n", dst1)fmt.Printf("Number of bytes written: %d\n", bytes_written)dst2 := make([]byte, ascii85.MaxEncodedLen(len(dst1)))ndst, nsrc, _ := ascii85.Decode(dst2, dst1, true)fmt.Printf("Decoded array: %s\n", dst2)fmt.Printf("Number of bytes written: %d\n", ndst)fmt.Printf("Number of bytes consumed: %d\n", nsrc)}
In the above example, we first do an ascii-85 encoding of src1
containing the string “Ascii85 encoding in Golang.” using ascii85.Encode()
and store the result in dst1
.
We then use the ascii85.Decode()
method that decodes dst1
and stores the result in dst2
. As you can observe, the Decode()
method returns the original string.
Free Resources