-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Define reader/writer interfaces with variant
- Loading branch information
Showing
8 changed files
with
399 additions
and
136 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
partiql-spi/src/main/java/org/partiql/spi/value/DatumReader.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,21 @@ | ||
package org.partiql.spi.value; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* The {@link DatumReader} interface is a low-level reader interface for reading streams of PartiQL data. | ||
* <br> | ||
* {@see java.io.Reader} | ||
* <br> | ||
* TODO | ||
* - public void reset(); | ||
* - public void skip(long n); | ||
*/ | ||
public interface DatumReader extends AutoCloseable { | ||
|
||
/** | ||
* @return next Datum or null. | ||
*/ | ||
@Nullable | ||
public Datum read(); | ||
} |
16 changes: 16 additions & 0 deletions
16
partiql-spi/src/main/java/org/partiql/spi/value/DatumWriter.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,16 @@ | ||
package org.partiql.spi.value; | ||
|
||
/** | ||
* The {@link DatumWriter} interface is a low-level writer interface for writing streams of PartiQL data. | ||
* <br> | ||
* {@see java.io.Writer} | ||
*/ | ||
public interface DatumWriter extends AutoCloseable { | ||
|
||
/** | ||
* Like java.io.Reader with combined `append` and `write` since this does not implement Appendable. | ||
* | ||
* @param datum to write. | ||
*/ | ||
public DatumWriter write(Datum datum); | ||
} |
43 changes: 43 additions & 0 deletions
43
partiql-spi/src/main/java/org/partiql/spi/value/Variant.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,43 @@ | ||
package org.partiql.spi.value; | ||
|
||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
/** | ||
* Variant is a {@link Datum} with the ability to pack and unpack a value. | ||
* | ||
* @param <T> | ||
*/ | ||
public interface Variant<T> extends Datum { | ||
|
||
/** | ||
* Unpack the inner variant value. | ||
* | ||
* @return T | ||
*/ | ||
T unpack(); | ||
|
||
/** | ||
* TODO move to writer? | ||
* <br> | ||
* Pack the variant into a byte array. | ||
* | ||
* @return byte[] | ||
*/ | ||
default byte[] pack() { | ||
throw new UnsupportedOperationException("variant does not have a byte[] encoding."); | ||
} | ||
|
||
/** | ||
* TODO move to writer? | ||
* <br> | ||
* Pack the variant into a byte array with the given charset. | ||
* | ||
* @param charset charset | ||
* @return byte[] | ||
*/ | ||
default byte[] pack(@NotNull Charset charset) { | ||
throw new UnsupportedOperationException("variant does not have an encoding for charset: " + charset.name()); | ||
} | ||
} |
Oops, something went wrong.