开发者

Get length to decoding Ascii85

ascii85 has a function to get the maximum length of an encoding MaxEncodedLen().

I think that it should have too a function to get the length at decoding like it has in Base64.

http://golang.org/pkg/encoding/ascii85开发者_JS百科/


Here's a function to calculate Go package ascii85 MaxDecodedLen() for n encoded bytes.

func MaxDecodedLen(n int) int {
    const binWordLen = 4
    return n * binWordLen
}

If all four bytes of a unencoded group are zero, they are represented by a single byte, the character z, instead of by five exclamation points (!!!!!). In some implementations, an unencoded group of spaces may be represented by the single character y.

ascii85.Decode(), unlike ascii85.Encode(), has number of bytes consumed (nsrc) and flush parameters, in addition to a number of bytes written (ndst) parameter, which allows the programmer to decode multiple blocks or a single block piece-by-piece. Therefore, a destination buffer of less than the MaxDecodedLen() may be used.


In my opinion,While encoding the MaxEncodedLen() is mandatory to know the number of bytes required to hold the encoded output (ie destination buffer size ).
Where in case of decoding ,the caller can pass the destination buffer of size equal to source buffer though the destination buffer can be lesser size.
Alternatively we can use the original source ie plain non-encoded buffer size,if the execution context/scope of encoding and decoding are same. Hence the expected function,MaxDecodedLen() is optional.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜