msgpack icon indicating copy to clipboard operation
msgpack copied to clipboard

add Decoder to read stream of messages

Open butonic opened this issue 2 years ago • 2 comments

I am trying to read multiple messages appended to a file. This PR adds a poor mans version of a decoder for an io.Reader. Poor man, because it reads the full file in memory, which is good enough for my use case. I also changed the fmt.Errorf("data is empty") error to an io.EOF erro, which is more idiomatic go. Let me know if I should leave that out of this PR.

butonic avatar Jul 07 '23 12:07 butonic

Hi.

I don't understand the intention of the PR, but I thought that if you want io.EOF, you should convert it when a decoding error happens.

see below.

// example
err := msgpack.Unmarshal(data, v)
if err.Error() == "data is empty" {
    return io.EOF // convert or wrap
}

shamaton avatar Jul 11 '23 13:07 shamaton

The idea is to be able to append msgpack records to a file. so you don't know how many records you get in advance.

butonic avatar Dec 07 '23 13:12 butonic