This repository was archived by the owner on Sep 9, 2023. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork 22
feat: adds ValueConverter utility and demo samples #108
Merged
Merged
Changes from 3 commits
Commits
Show all changes
16 commits Select commit Hold shift + click to select a range
a484ba6 feat: adds value converter utility class and demo samples
telpirion 1df941a feat: samples updated for EJCL
telpirion 980e089 fix: removed local file references
telpirion 393458d feat: adds ValueConverter tests
telpirion 4346e91 fix: per reviewer
telpirion 098255f fix: removed unused imports
telpirion 3e37edf Merge branch 'master' into enhanced-lib2
telpirion e7b251d fix: lint
telpirion 1280f62 fix: Java ver mismatch
telpirion 52aa8cf fix: lint
telpirion 1d41681 fix: more lint
telpirion 50d9fb6 fix: test dependency
telpirion 5cd1bdf fix: samples test
telpirion a6a1972 fix: per reviewer
telpirion 2dde132 Update google-cloud-aiplatform/src/test/java/com/google/cloud/aiplatf…
telpirion c39ff3d fix: lint
telpirion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
48 changes: 48 additions & 0 deletions 48 ...-aiplatform/src/main/java/com/google/cloud/aiplatform/v1beta1/utility/ValueConverter.java
This file contains hidden or 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,48 @@ | ||
| package com.google.cloud.aiplatform.v1beta1.utility; | ||
| | ||
| import com.google.protobuf.InvalidProtocolBufferException; | ||
| import com.google.protobuf.Message; | ||
| import com.google.protobuf.Value; | ||
| import com.google.protobuf.util.JsonFormat; | ||
| | ||
| /** | ||
| * Exposes utility methods for converting AI Platform messages to and | ||
| * from {@com.google.protobuf.Value} objects. | ||
| */ | ||
| public class ValueConverter { | ||
| | ||
| /** | ||
| * An empty {@com.google.protobuf.Value} message. | ||
| */ | ||
| public static final Value EMPTY_VALUE = Value.newBuilder().build(); | ||
chingor13 marked this conversation as resolved. Outdated Show resolved Hide resolved | ||
| | ||
| /** | ||
| * Converts a message type to a {@com.google.protobuf.Value}. | ||
| * | ||
| * @param message the message to convert | ||
| * @return the message as a {@com.google.protobuf.Value} | ||
| * @throws InvalidProtocolBufferException | ||
| */ | ||
| public static Value toValue(Message message) throws InvalidProtocolBufferException { | ||
| String jsonString = JsonFormat.printer().print(message); | ||
| Value.Builder value = Value.newBuilder(); | ||
| JsonFormat.parser().merge(jsonString, value); | ||
| return value.build(); | ||
| } | ||
| | ||
| /** | ||
| * Converts a {@com.google.protobuf.Value} to a {@com.google.protobuf.Message} | ||
| * of the provided {@com.google.protobuf.Message.Builder}. | ||
| * | ||
| * @param messageBuilder a builder for the message type | ||
| * @param value the Value to convert to a message | ||
| * @return the value as a message | ||
| * @throws InvalidProtocolBufferException | ||
| */ | ||
| public static Message fromValue(Message.Builder messageBuilder, Value value) | ||
| throws InvalidProtocolBufferException { | ||
| String valueString = JsonFormat.printer().print(value); | ||
| JsonFormat.parser().merge(valueString, messageBuilder); | ||
| return messageBuilder.build(); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.