-
Notifications
You must be signed in to change notification settings - Fork 1.8k
AVRO-4258: [java] remove some allocations from decoder.getBytes() and Utf8 handling #3776
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
059a5b0
ed5e115
9fa67ec
2d638f7
e5ef7b2
bf69352
2b76d23
9b12285
40c0a54
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import java.io.IOException; | ||
| import java.nio.ByteBuffer; | ||
|
|
||
| import org.apache.avro.AvroTypeException; | ||
| import org.apache.avro.util.Utf8; | ||
|
|
||
| /** | ||
|
|
@@ -41,6 +42,8 @@ | |
|
|
||
| public abstract class Decoder { | ||
|
|
||
| protected static final byte[] EMPTY_BYTES = new byte[0]; | ||
|
|
||
| /** | ||
| * "Reads" a null value. (Doesn't actually read anything, but advances the state | ||
| * of the parser if the implementation is stateful.) | ||
|
|
@@ -126,6 +129,22 @@ public abstract class Decoder { | |
| */ | ||
| public abstract ByteBuffer readBytes(ByteBuffer old) throws IOException; | ||
|
|
||
| /** | ||
| * Reads a byte-string written by {@link Encoder#writeBytes}. | ||
| * <p> | ||
| * This is useful when you want to avoid the creation of a ByteBuffer, and only | ||
| * want the byte[], e.g.: | ||
| * | ||
| * <pre> | ||
| * ByteBuffer buffer = decoder.readBytes(null); | ||
| * byte[] array = buffer.array(); | ||
| * </pre> | ||
| * | ||
| * @throws AvroTypeException If this is a stateful reader and byte-string is not | ||
| * the type of the next value to be read | ||
| */ | ||
| public abstract byte[] readBytes() throws IOException; | ||
|
Comment on lines
+131
to
+145
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not aware of the expectations on up/downgrade, and if this is appropriate. Happy to make a change if i is the right thing to do, but it looks to me as if if that is the case the default implementation should be removed on the next opportunity for a braking change, be that major or minor version, based on the policy of the avro project
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| /** | ||
| * Discards a byte-string written by {@link Encoder#writeBytes}. | ||
| * | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.