[ 
https://issues.apache.org/jira/browse/HDDS-14655?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18059431#comment-18059431
 ] 

Tsz-wo Sze commented on HDDS-14655:
-----------------------------------

- For the simple implementations such as ScmBooleanCodec, ScmByteStringCodec, 
etc., we may fix them in the JIRA.
- For some more complicated cases such as ScmGeneratedMessageCodec, we may use 
Object as the generic type and fix them in separated JIRAs.

See 
https://issues.apache.org/jira/secure/attachment/13080869/HDDS-14655_idea.patch

> Add a generic type to ScmCodec
> ------------------------------
>
>                 Key: HDDS-14655
>                 URL: https://issues.apache.org/jira/browse/HDDS-14655
>             Project: Apache Ozone
>          Issue Type: Sub-task
>          Components: SCM HA
>            Reporter: Tsz-wo Sze
>            Priority: Major
>         Attachments: HDDS-14655_idea.patch
>
>
> Add a generic type:
> {code:java}
> public interface ScmCodec<T> {
>   ByteString serialize(T object) throws InvalidProtocolBufferException;
>   T deserialize(Class<?> type, ByteString value) throws 
> InvalidProtocolBufferException;
> }
> {code}
> Then, the subclass implementations does not have to cast the objects.
> {code:java}
> public class ScmBigIntegerCodec implements ScmCodec<BigInteger> {
>   @Override
>   public ByteString serialize(BigInteger object) {
>     // BigInteger returns a new byte[].
>     return UnsafeByteOperations.unsafeWrap(object.toByteArray());
>   }
>   @Override
>   public BigInteger deserialize(Class<?> type, ByteString value) {
>     return new BigInteger(value.toByteArray());
>   }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to