+ public ReadDataReply() {
+ }
+
+ public ReadDataReply(NormalizedNode<?, ?> normalizedNode, short version) {
+ super(version);
+ this.normalizedNode = normalizedNode;
+ }
+
+ public NormalizedNode<?, ?> getNormalizedNode() {
+ return normalizedNode;
+ }
+
+ @Override
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+ normalizedNode = SerializationUtils.deserializeNormalizedNode(in);
+ }
+
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+ SerializationUtils.serializeNormalizedNode(normalizedNode, out);
+ }
+
+ @Override
+ public Object toSerializable() {
+ if(getVersion() >= DataStoreVersions.LITHIUM_VERSION) {
+ return this;
+ } else {
+ return toSerializableReadDataReply(normalizedNode);
+ }
+ }
+
+ private static ShardTransactionMessages.ReadDataReply toSerializableReadDataReply(
+ NormalizedNode<?, ?> normalizedNode) {
+ if(normalizedNode != null) {
+ return ShardTransactionMessages.ReadDataReply.newBuilder()
+ .setNormalizedNode(new NormalizedNodeToNodeCodec(null)
+ .encode(normalizedNode).getNormalizedNode()).build();
+ } else {
+ return ShardTransactionMessages.ReadDataReply.newBuilder().build();
+
+ }
+ }
+
+ public static ReadDataReply fromSerializable(Object serializable) {
+ if(serializable instanceof ReadDataReply) {
+ return (ReadDataReply) serializable;
+ } else {
+ ShardTransactionMessages.ReadDataReply o =
+ (ShardTransactionMessages.ReadDataReply) serializable;
+ return new ReadDataReply(new NormalizedNodeToNodeCodec(null).decode(o.getNormalizedNode()),
+ DataStoreVersions.HELIUM_2_VERSION);
+ }
+ }
+
+ public static ByteString fromSerializableAsByteString(Object serializable) {
+ if(serializable instanceof ReadDataReply) {
+ ReadDataReply r = (ReadDataReply)serializable;
+ return toSerializableReadDataReply(r.getNormalizedNode()).toByteString();
+ } else {
+ ShardTransactionMessages.ReadDataReply o =
+ (ShardTransactionMessages.ReadDataReply) serializable;
+ return o.getNormalizedNode().toByteString();
+ }
+ }
+
+ public static boolean isSerializedType(Object message) {
+ return SERIALIZABLE_CLASS.isAssignableFrom(message.getClass()) ||
+ message instanceof ShardTransactionMessages.ReadDataReply;
+ }