Repository navigation
feat(encoding): Add MediaType::encode - #384
Conversation
2fa9191 to
a150ada
Compare
krisztianfekete
left a comment
There was a problem hiding this comment.
Thanks, added a few small comments!
| } | ||
| } | ||
|
|
||
| /// Encodes `registry` into `writer` in the format of this media type. |
There was a problem hiding this comment.
Can we document that if this fails, part of the output may already be in writer, so a handler must not send the buffer it was writing into?
| registry: &Registry, | ||
| writer: &mut W, |
There was a problem hiding this comment.
Nit: text::encode and prometheus_text::encode take the writer first, but have no hard opinion on this one.
There was a problem hiding this comment.
Updated, better to be consistent
| let body = prometheus_protobuf::encode_to_vec(registry)?; | ||
| writer.write_all(&body)?; |
There was a problem hiding this comment.
This holds the whole protobuf body 2x. We could avoid with encoding each family into a reused scratch buffer. Fine as a follow-up though, but please open an issue to track this in that case.
There was a problem hiding this comment.
Yes I was thinking about this before but just forgot to revisit it, changed in 3106abd
| } | ||
|
|
||
| #[test] | ||
| fn encodes_formats() { |
There was a problem hiding this comment.
Can you please add a test with a writer that fails, asserting EncodeError::Io and that the original ErrorKind is kept? That error path has no test.
There was a problem hiding this comment.
Added test to cover it
There was a problem hiding this comment.
Please move it to [Unreleased].
There was a problem hiding this comment.
Yes, that's what I meant, sorry for the weird wording. Thanks!
Encodes a registry into an io::Write in the negotiated format, so callers don't have to match on the format themselves. Signed-off-by: Kalle <23356117+kalleep@users.noreply.github.com>
Signed-off-by: Kalle <23356117+kalleep@users.noreply.github.com>
Signed-off-by: Kalle <23356117+kalleep@users.noreply.github.com>
Signed-off-by: Kalle <23356117+kalleep@users.noreply.github.com>
Signed-off-by: Kalle <23356117+kalleep@users.noreply.github.com>
Signed-off-by: Kalle <23356117+kalleep@users.noreply.github.com>
Signed-off-by: Kalle <23356117+kalleep@users.noreply.github.com>
Signed-off-by: Kalle <23356117+kalleep@users.noreply.github.com>
a150ada to
3106abd
Compare
Follow-up to #381. Adds
MediaType::encode, so callers don't have to match on the format themselves.encode writes to any io::Write. The text formats write straight into the writer, so the output is not buffered a second time. The protobuf format is encoded with encode_to_vec and then written.