-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IPROTO-266 Allow for custom Encoder/Decoder implementations for TagWr…
…iter/TagReader
- Loading branch information
Showing
10 changed files
with
377 additions
and
262 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
core/src/main/java/org/infinispan/protostream/Decoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package org.infinispan.protostream; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
|
||
public interface Decoder { | ||
int getEnd(); | ||
|
||
int getPos(); | ||
|
||
byte[] getBufferArray() throws IOException; | ||
|
||
boolean isAtEnd() throws IOException; | ||
|
||
int readTag() throws IOException; | ||
|
||
void checkLastTagWas(int expectedTag) throws IOException; | ||
|
||
boolean skipField(int tag) throws IOException; | ||
|
||
void skipVarint() throws IOException; | ||
|
||
void skipRawBytes(int length) throws IOException; | ||
|
||
String readString() throws IOException; | ||
|
||
byte readRawByte() throws IOException; | ||
|
||
byte[] readRawByteArray(int length) throws IOException; | ||
|
||
ByteBuffer readRawByteBuffer(int length) throws IOException; | ||
|
||
int readVarint32() throws IOException; | ||
|
||
long readVarint64() throws IOException; | ||
|
||
int readFixed32() throws IOException; | ||
|
||
long readFixed64() throws IOException; | ||
|
||
int pushLimit(int newLimit) throws IOException; | ||
|
||
void popLimit(int oldLimit); | ||
|
||
Decoder decoderFromLength(int length) throws IOException; | ||
|
||
/** | ||
* Sets a hard limit on how many bytes we can continue to read while parsing a message from current position. This is | ||
* useful to prevent corrupted or malicious messages with wrong length values to abuse memory allocation. Initially | ||
* this limit is set to {@code Integer.MAX_INT}, which means the protection mechanism is disabled by default. | ||
* The limit is only useful when processing streams. Setting a limit for a decoder backed by a byte array is useless | ||
* because the memory allocation already happened. | ||
*/ | ||
int setGlobalLimit(int globalLimit); | ||
} |
50 changes: 50 additions & 0 deletions
50
core/src/main/java/org/infinispan/protostream/Encoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.infinispan.protostream; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
|
||
public interface Encoder { | ||
void flush() throws IOException; | ||
|
||
void close() throws IOException; | ||
|
||
int remainingSpace(); | ||
|
||
void writeUInt32Field(int fieldNumber, int value) throws IOException; | ||
|
||
void writeUInt64Field(int fieldNumber, long value) throws IOException; | ||
|
||
void writeFixed32Field(int fieldNumber, int value) throws IOException; | ||
|
||
void writeFixed64Field(int fieldNumber, long value) throws IOException; | ||
|
||
void writeBoolField(int fieldNumber, boolean value) throws IOException; | ||
|
||
void writeLengthDelimitedField(int fieldNumber, int length) throws IOException; | ||
|
||
void writeVarint32(int value) throws IOException; | ||
|
||
void writeVarint64(long value) throws IOException; | ||
|
||
void writeFixed32(int value) throws IOException; | ||
|
||
void writeFixed64(long value) throws IOException; | ||
|
||
void writeByte(byte value) throws IOException; | ||
|
||
void writeBytes(byte[] value, int offset, int length) throws IOException; | ||
|
||
void writeBytes(ByteBuffer value) throws IOException; | ||
|
||
default int skipFixedVarint() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
default void writePositiveFixedVarint(int pos) { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
default boolean supportsFixedVarint() { | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package org.infinispan.protostream; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
|
||
|
@@ -9,14 +10,14 @@ | |
* @author [email protected] | ||
* @since 4.4 | ||
*/ | ||
public interface TagWriter extends RawProtoStreamWriter { | ||
public interface TagWriter extends RawProtoStreamWriter, Closeable { | ||
|
||
// start low level ops | ||
void flush() throws IOException; | ||
|
||
/** | ||
* Invoke after done with writer, this implies a flush if necessary | ||
* It is necessary to invoke this on a writer returned from {@link #subWriter(int)} to actually push the data | ||
* It is necessary to invoke this on a writer returned from {@link #subWriter(int, boolean)} to actually push the data | ||
*/ | ||
void close() throws IOException; | ||
|
||
|
@@ -99,9 +100,12 @@ default void writeBytes(int number, byte[] value) throws IOException { | |
|
||
/** | ||
* Used to write a sub message that can be optimized by implementation. When the sub writer is complete, flush | ||
* should be invoked to ensure | ||
* @return | ||
* @throws IOException | ||
* should be invoked to ensure bytes are written and close should be invoked to free any resources related to the | ||
* context (note close will flush as well) | ||
* @param number the message number of the sub message | ||
* @param nested whether this is a nested message or a new one | ||
* @return a write context for a sub message | ||
* @throws IOException exception if there is an issue | ||
*/ | ||
TagWriter subWriter(int number, boolean nested) throws IOException; | ||
ProtobufTagMarshaller.WriteContext subWriter(int number, boolean nested) throws IOException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.