Closed jyasskin closed 6 years ago
It might also be reasonable to special-case empty payloads and omit the record size from them too.
Hah. Yeah, I guess the hash of the empty record (still hash("\0")) is perfectly well-defined even if you don't have a record size...
For completeness, another option is to special-case empty payloads by including the record-size but saying that the last record may be 0 octets long if it is the first/only record. Or you could just say that the last record is always allowed to be between 0 and rs bytes long, but that means, for a given body and record size, there are two possible encodings if the body is a multiple of rs bytes long.
Saying the last record is between 0 and rs-1 bytes keeps the parsing logic uniform, which is a nice simplification, so that's my weak preference. The other options save 32 bytes for multiple-of-rs bodies, but one expects 32 is a relatively small fraction of rs. But I don't actually care, so whichever folks prefer.
@davidben points out that "The last record is between 1 and "rs" octets in length" doesn't provide a way to represent an empty payload.
He suggests saying that the last record is instead between 0 and rs-1 bytes long, in which case a payload that's a multiple of rs bytes long gets a hash("\0") at the very end.
It might also be reasonable to special-case empty payloads and omit the record size from them too.