-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to Binary input/output type
Signed-off-by: Andres Gomez Ferrer <[email protected]>
- Loading branch information
1 parent
c8617fe
commit 065957a
Showing
19 changed files
with
358 additions
and
10 deletions.
There are no files selected for viewing
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,47 @@ | ||
/* | ||
* Copyright 2020-2021 Flyte Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.flyte.api.v1; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
/** | ||
* A simple byte array with a tag to help different parts of the system communicate about what is in | ||
* the byte array. It's strongly advisable that consumers of this type define a unique tag and | ||
* validate the tag before parsing the data. | ||
*/ | ||
@AutoValue | ||
public abstract class Binary { | ||
public static final String TAG_FIELD = "tag"; | ||
public static final String VALUE_FIELD = "value"; | ||
|
||
public abstract byte[] value(); | ||
|
||
public abstract String tag(); | ||
|
||
public static Builder builder() { | ||
return new AutoValue_Binary.Builder(); | ||
} | ||
|
||
@AutoValue.Builder | ||
public abstract static class Builder { | ||
public abstract Builder value(byte[] value); | ||
|
||
public abstract Builder tag(String tag); | ||
|
||
public abstract Binary build(); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -24,5 +24,6 @@ public enum SimpleType { | |
BOOLEAN, | ||
DATETIME, | ||
DURATION, | ||
STRUCT | ||
STRUCT, | ||
BINARY | ||
} |
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
51 changes: 51 additions & 0 deletions
51
flytekit-jackson/src/main/java/org/flyte/flytekit/jackson/serializers/BinarySerializer.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,51 @@ | ||
/* | ||
* Copyright 2020-2023 Flyte Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.flyte.flytekit.jackson.serializers; | ||
|
||
import static org.flyte.flytekit.jackson.serializers.SdkBindingDataSerializationProtocol.VALUE; | ||
|
||
import com.fasterxml.jackson.core.JsonGenerator; | ||
import com.fasterxml.jackson.databind.SerializerProvider; | ||
import java.io.IOException; | ||
import java.util.Base64; | ||
import org.flyte.api.v1.Binary; | ||
import org.flyte.api.v1.Literal; | ||
import org.flyte.api.v1.LiteralType; | ||
import org.flyte.api.v1.Scalar.Kind; | ||
|
||
public class BinarySerializer extends ScalarSerializer { | ||
public BinarySerializer( | ||
JsonGenerator gen, | ||
String key, | ||
Literal value, | ||
SerializerProvider serializerProvider, | ||
LiteralType literalType) { | ||
super(gen, key, value, serializerProvider, literalType); | ||
} | ||
|
||
@Override | ||
void serializeScalar() throws IOException { | ||
gen.writeObject(Kind.BINARY); | ||
gen.writeFieldName(VALUE); | ||
gen.writeStartObject(); | ||
gen.writeFieldName(Binary.TAG_FIELD); | ||
gen.writeString(value.scalar().binary().tag()); | ||
gen.writeFieldName(Binary.VALUE_FIELD); | ||
gen.writeString(Base64.getEncoder().encodeToString(value.scalar().binary().value())); | ||
gen.writeEndObject(); | ||
} | ||
} |
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.