Package com.oracle.coherence.grpc
Class BinaryHelper
java.lang.Object
com.oracle.coherence.grpc.BinaryHelper
A helper class of methods to convert between
Binary
instances and proto-buffer byte values.- Since:
- 20.06
- Author:
- Mahesh Kannan 2019.11.01, Jonathan Knight 2019.11.07
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.google.protobuf.EmptySingletonEmpty.static final com.google.protobuf.ByteStringSingleton emptyByteString. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TfromBinary(Binary binary, Serializer serializer) Deserialize a serializedBinary.static <T> TfromByteString(com.google.protobuf.ByteString bytes, Serializer serializer) A utility method to deserialize aByteStringto an Object.static <T> TfromBytesValue(com.google.protobuf.BytesValue bytes, Serializer serializer) A utility method to deserialize aBytesValueto an Object.static BinarytoBinary(com.google.protobuf.ByteString bytes) Convert aByteStringto aBinary.static BinarytoBinary(com.google.protobuf.BytesValue bytes) Convert aBytesValueto aBinary.static BinarytoBinaryKey(com.google.protobuf.ByteString bytes) static BinarytoBinaryKey(com.google.protobuf.BytesValue bytes) static BinarytoBinaryKey(Binary binary) static com.google.protobuf.ByteStringtoByteString(Binary binary) Convert aBinaryto aByteString.static com.google.protobuf.ByteStringtoByteString(Object value, Serializer serializer) Serialize the specified value to aByteString.static com.google.protobuf.BytesValuetoBytesValue(Binary binary) Convert aBinaryto aBytesValue.static com.google.protobuf.BytesValuetoBytesValue(Object value, Serializer serializer) Serialize the specified value to aBytesValue.static com.oracle.coherence.grpc.EntrytoEntry(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value) Create anEntrycontaining the specified key and value.static com.oracle.coherence.grpc.EntrytoEntry(Map.Entry<?, ?> entry, Serializer serializer) Create anEntryfrom aMap.Entry.static List<com.oracle.coherence.grpc.Entry> toEntryList(Map<?, ?> map, Serializer serializer) Create aMapto a list ofEntryinstances.static ReadBuffertoReadBuffer(com.google.protobuf.ByteString bytes) Convert aByteStringto aReadBuffer.static Stream<com.google.protobuf.StringValue> toStringValueStream(Iterable<?> iterable)
-
Field Details
-
EMPTY
public static final com.google.protobuf.Empty EMPTYSingletonEmpty. -
EMPTY_BYTE_STRING
public static final com.google.protobuf.ByteString EMPTY_BYTE_STRINGSingleton emptyByteString.
-
-
Method Details
-
toBinaryKey
Convert aBytesValueto aBinarythat is decorated to make theBinarysuitable for use as a cache key.- Parameters:
bytes- theBytesValueto convert- Returns:
- a
Binarythat is suitable for use as a cache key - Throws:
NullPointerException- if theBytesValueisnull
-
toBinaryKey
Convert aByteStringto aBinarythat is decorated to make theBinarysuitable for use as a cache key.- Parameters:
bytes- theByteStringto convert- Returns:
- a
Binarythat is suitable for use as a cache key - Throws:
NullPointerException- if theByteStringisnull
-
toBinaryKey
- Parameters:
binary- theBinaryto convert- Returns:
- a
Binarythat is suitable for use as a cache key - Throws:
NullPointerException- if theBinaryisnull
-
toBinary
Convert aBytesValueto aBinary.The
BytesValueis converted to a list ofByteBuffers which are then converted toByteBufferReadBuffers and finally to aBinaryto avoid copying byte arrays.- Parameters:
bytes- theBytesValueto convert- Returns:
- a
Binarycontaining the bytes of theBytesValue - Throws:
NullPointerException- if theBytesValueisnull
-
toBinary
Convert aByteStringto aBinary.The
ByteStringis converted to a list ofByteBuffers which are then converted toByteBufferReadBuffers and finally to aBinaryto avoid copying byte arrays.- Parameters:
bytes- theByteStringto convert- Returns:
- a
Binarycontaining the bytes of theByteString - Throws:
NullPointerException- if theByteStringisnull
-
toReadBuffer
Convert aByteStringto aReadBuffer.The
ByteStringis converted to a list ofByteBuffers which are then converted toByteBufferReadBuffers and finally to aBinaryto avoid copying byte arrays.- Parameters:
bytes- theByteStringto convert- Returns:
- a
ReadBuffercontaining the bytes of theByteString - Throws:
NullPointerException- if theByteStringisnull
-
fromBinary
Deserialize a serializedBinary.- Type Parameters:
T- the type of the original object theBinaryrepresents- Parameters:
binary- theBinaryto deserializeserializer- theSerializerto use- Returns:
- the deserialized
Binaryvalue ornullif theBinaryisnull
-
toBytesValue
-
toByteString
-
fromBytesValue
A utility method to deserialize aBytesValueto an Object.- Type Parameters:
T- the expected value type- Parameters:
bytes- theBytesValueto deserialize an Object.serializer- theSerializerto use to convert the binary stream to an object- Returns:
- an object from the specified
BytesValue
-
fromByteString
A utility method to deserialize aByteStringto an Object.- Type Parameters:
T- the expected value type- Parameters:
bytes- theByteStringto deserialize an Object.serializer- theSerializerto use to convert the binary stream to an object- Returns:
- an object from the specified
ByteString
-
toBytesValue
Serialize the specified value to aBytesValue.- Parameters:
value- the value to serializeserializer- theSerializerto use- Returns:
- the serialized value as a
BytesValue
-
toByteString
Serialize the specified value to aByteString.- Parameters:
value- the value to serializeserializer- theSerializerto use- Returns:
- the serialized value as a
ByteString
-
toEntryList
public static List<com.oracle.coherence.grpc.Entry> toEntryList(Map<?, ?> map, Serializer serializer) Create aMapto a list ofEntryinstances.- Parameters:
map- theMapto convert to a list ofEntryinstancesserializer- theSerializerto use- Returns:
- a list of
Entryinstances - Throws:
NullPointerException- if the map isnull
-
toEntry
Create anEntryfrom aMap.Entry.- Parameters:
entry- theMap.Entryto convert to anEntryserializer- theSerializerto use- Returns:
- an
Entrycontaining the specified key and value - Throws:
NullPointerException- if the entry isnull
-
toEntry
public static com.oracle.coherence.grpc.Entry toEntry(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value) Create anEntrycontaining the specified key and value.- Parameters:
key- the entry's keyvalue- the entry's value- Returns:
- an
Entrycontaining the specified key and value
-
toStringValueStream
-