Skip to content

add Decoder to read stream of messages #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

butonic
Copy link

@butonic butonic commented Jul 7, 2023

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.

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
@shamaton
Copy link
Owner

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
}

@butonic
Copy link
Author

butonic commented Dec 7, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants