获取解码Ascii85的长度

huangapple go评论78阅读模式
英文:

Get length to decoding Ascii85

问题

ascii85有一个函数可以获取编码的最大长度MaxEncodedLen()

我认为它也应该有一个函数来获取解码的长度,就像Base64中一样。

http://golang.org/pkg/encoding/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/

答案1

得分: 0

在我看来,编码时,必须知道编码输出所需的字节数,这可以通过调用MaxEncodedLen()来实现(即目标缓冲区的大小)。
而在解码时,调用者可以将目标缓冲区的大小设置为与源缓冲区相等,尽管目标缓冲区的大小可以更小。
或者,如果编码和解码的执行上下文/范围相同,我们可以使用原始源即非编码缓冲区的大小。
因此,预期的函数MaxDecodedLen()是可选的。

英文:

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.

答案2

得分: 0

这是一个用于计算Go package ascii85 中的 MaxDecodedLen() 函数,用于计算 n 个编码字节的长度。

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

如果一个未编码组的四个字节都是零,则用单个字节 z 表示,而不是用五个感叹号 (!!!!!) 表示。在某些实现中,一组未编码的空格可以用单个字符 y 表示。

ascii85.Encode() 不同,ascii85.Decode() 还有消耗的字节数 (nsrc) 和 flush 参数,除了写入的字节数 (ndst) 参数,这使得程序员可以逐块或逐个片段地解码多个块或单个块。因此,可以使用小于 MaxDecodedLen() 的目标缓冲区。

英文:

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.

huangapple
  • 本文由 发表于 2010年4月29日 18:36:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/2736604.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定