whyrusleeping / cbor-gen

Codegen for cbor codecs on your types
MIT License
35 stars 25 forks source link

Fix readByteBuf #59

Closed MarcoPolo closed 2 years ago

MarcoPolo commented 2 years ago

readByteBuf was incorrectly return the error (EOF) before returning the first byte read. It is a valid for an io.Reader to return both n == 1 and err == EOF (see https://pkg.go.dev/io#Reader). But readByteBuf dropped the read byte and instead returned EOF.

This checks if we've read a byte and return that first rather than the error. If we're at EOF the next read will return n == 0 and EOF.

Also adds a couple test cases.

MarcoPolo commented 2 years ago

heh this is actually also addressed in: https://github.com/whyrusleeping/cbor-gen/pull/44/files#diff-8b7f25bac2ae04c2ce2abb628c6aa28103fd113103a62f3e9d232fa995684915R291-R300

MarcoPolo commented 2 years ago

Closing in favor of https://github.com/whyrusleeping/cbor-gen/pull/60