-
Notifications
You must be signed in to change notification settings - Fork 541
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
Support printing to arbitrary Writers #537
Conversation
Current coverage is 82.67% (diff: 100%)@@ master #537 diff @@
==========================================
Files 70 70
Lines 1974 2014 +40
Methods 1828 1874 +46
Messages 0 0
Branches 146 140 -6
==========================================
+ Hits 1623 1665 +42
+ Misses 351 349 -2
Partials 0 0
|
printJsonAtDepth(writer)(json, 0) | ||
|
||
writer.close() | ||
bytes.toByteArray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish we could avoid copying here. Even though there is no API to retrieve the underlying buffer directly, people seem to use this simple trick to do that. Please, note that this means we'd need to change the return type to ByteBuffer
since the underlying Array[Byte]
may contain more bytes than we need so we have to crop it.
I think we can also expose that as a standalone method (printByteBuffer
) if we're worried about this extra complexity. What do you think @travisbrown?
Ah, good point, @vkostyukov. I've just pushed an update—what do you think? |
Looks great! I really like how simple |
Ugh, was just running Scala.js tests for the 0.7.0-M2 release and get this: [error] Referring to non-existent method java.io.BufferedWriter.<init>(java.io.Writer)
[error] called from io.circe.Printer.prettyByteBuffer(io.circe.Json)java.nio.ByteBuffer I guess we'll have to make this a JVM-only method—I'll get started on that asap. |
Addresses #536. In addition to the new
prettyBytes
I've made a few other small changes that simplify things a bit and seem to give us a few percent more throughput in the benchmarks.I'm not currently exposing the ability for users to print to their own
Appendable
s. I'm not totally opposed to the idea, but I'd prefer not to add methods that are fundamentally about mutation unless there's a really clear need.