martinthomson / http-mice

A progressive integrity content encoding for HTTP
3 stars 2 forks source link

Describe how to represent an empty payload #3

Closed jyasskin closed 6 years ago

jyasskin commented 6 years ago

@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.

davidben commented 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...

davidben commented 6 years ago

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.