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
Modifier and TypeFieldDescriptionstatic final com.google.protobuf.Empty
SingletonEmpty
.static final com.google.protobuf.ByteString
Singleton emptyByteString
. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> T
fromBinary
(Binary binary, Serializer serializer) Deserialize a serializedBinary
.static <T> T
fromByteString
(com.google.protobuf.ByteString bytes, Serializer serializer) A utility method to deserialize aByteString
to an Object.static <T> T
fromBytesValue
(com.google.protobuf.BytesValue bytes, Serializer serializer) A utility method to deserialize aBytesValue
to an Object.static Binary
toBinary
(com.google.protobuf.ByteString bytes) Convert aByteString
to aBinary
.static Binary
toBinary
(com.google.protobuf.BytesValue bytes) Convert aBytesValue
to aBinary
.static Binary
toBinaryKey
(com.google.protobuf.ByteString bytes) static Binary
toBinaryKey
(com.google.protobuf.BytesValue bytes) static Binary
toBinaryKey
(Binary binary) static com.google.protobuf.ByteString
toByteString
(Binary binary) Convert aBinary
to aByteString
.static com.google.protobuf.ByteString
toByteString
(Object value, Serializer serializer) Serialize the specified value to aByteString
.static com.google.protobuf.BytesValue
toBytesValue
(Binary binary) Convert aBinary
to aBytesValue
.static com.google.protobuf.BytesValue
toBytesValue
(Object value, Serializer serializer) Serialize the specified value to aBytesValue
.static com.oracle.coherence.grpc.Entry
toEntry
(com.google.protobuf.ByteString key, com.google.protobuf.ByteString value) Create anEntry
containing the specified key and value.static com.oracle.coherence.grpc.Entry
toEntry
(Map.Entry<?, ?> entry, Serializer serializer) Create anEntry
from aMap.Entry
.static List
<com.oracle.coherence.grpc.Entry> toEntryList
(Map<?, ?> map, Serializer serializer) Create aMap
to a list ofEntry
instances.static ReadBuffer
toReadBuffer
(com.google.protobuf.ByteString bytes) Convert aByteString
to 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 aBytesValue
to aBinary
that is decorated to make theBinary
suitable for use as a cache key.- Parameters:
bytes
- theBytesValue
to convert- Returns:
- a
Binary
that is suitable for use as a cache key - Throws:
NullPointerException
- if theBytesValue
isnull
-
toBinaryKey
Convert aByteString
to aBinary
that is decorated to make theBinary
suitable for use as a cache key.- Parameters:
bytes
- theByteString
to convert- Returns:
- a
Binary
that is suitable for use as a cache key - Throws:
NullPointerException
- if theByteString
isnull
-
toBinaryKey
- Parameters:
binary
- theBinary
to convert- Returns:
- a
Binary
that is suitable for use as a cache key - Throws:
NullPointerException
- if theBinary
isnull
-
toBinary
Convert aBytesValue
to aBinary
.The
BytesValue
is converted to a list ofByteBuffer
s which are then converted toByteBufferReadBuffer
s and finally to aBinary
to avoid copying byte arrays.- Parameters:
bytes
- theBytesValue
to convert- Returns:
- a
Binary
containing the bytes of theBytesValue
- Throws:
NullPointerException
- if theBytesValue
isnull
-
toBinary
Convert aByteString
to aBinary
.The
ByteString
is converted to a list ofByteBuffer
s which are then converted toByteBufferReadBuffer
s and finally to aBinary
to avoid copying byte arrays.- Parameters:
bytes
- theByteString
to convert- Returns:
- a
Binary
containing the bytes of theByteString
- Throws:
NullPointerException
- if theByteString
isnull
-
toReadBuffer
Convert aByteString
to aReadBuffer
.The
ByteString
is converted to a list ofByteBuffer
s which are then converted toByteBufferReadBuffer
s and finally to aBinary
to avoid copying byte arrays.- Parameters:
bytes
- theByteString
to convert- Returns:
- a
ReadBuffer
containing the bytes of theByteString
- Throws:
NullPointerException
- if theByteString
isnull
-
fromBinary
Deserialize a serializedBinary
.- Type Parameters:
T
- the type of the original object theBinary
represents- Parameters:
binary
- theBinary
to deserializeserializer
- theSerializer
to use- Returns:
- the deserialized
Binary
value ornull
if theBinary
isnull
-
toBytesValue
-
toByteString
-
fromBytesValue
A utility method to deserialize aBytesValue
to an Object.- Type Parameters:
T
- the expected value type- Parameters:
bytes
- theBytesValue
to deserialize an Object.serializer
- theSerializer
to use to convert the binary stream to an object- Returns:
- an object from the specified
BytesValue
-
fromByteString
A utility method to deserialize aByteString
to an Object.- Type Parameters:
T
- the expected value type- Parameters:
bytes
- theByteString
to deserialize an Object.serializer
- theSerializer
to 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
- theSerializer
to use- Returns:
- the serialized value as a
BytesValue
-
toByteString
Serialize the specified value to aByteString
.- Parameters:
value
- the value to serializeserializer
- theSerializer
to use- Returns:
- the serialized value as a
ByteString
-
toEntryList
public static List<com.oracle.coherence.grpc.Entry> toEntryList(Map<?, ?> map, Serializer serializer) Create aMap
to a list ofEntry
instances.- Parameters:
map
- theMap
to convert to a list ofEntry
instancesserializer
- theSerializer
to use- Returns:
- a list of
Entry
instances - Throws:
NullPointerException
- if the map isnull
-
toEntry
Create anEntry
from aMap.Entry
.- Parameters:
entry
- theMap.Entry
to convert to anEntry
serializer
- theSerializer
to use- Returns:
- an
Entry
containing 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 anEntry
containing the specified key and value.- Parameters:
key
- the entry's keyvalue
- the entry's value- Returns:
- an
Entry
containing the specified key and value
-
toStringValueStream
-