Add new cds-access-api proxies
[controller.git] / opendaylight / md-sal / cds-access-api / src / main / java / org / opendaylight / controller / cluster / access / commands / SkipTransactionsRequest.java
index 3b97bb98170c762a7a5d70bf1df0300f30b60510..54fdfc581a7d0b4c595b66853bc9be589c1dce2d 100644 (file)
@@ -11,12 +11,15 @@ import akka.actor.ActorRef;
 import com.google.common.base.MoreObjects.ToStringHelper;
 import com.google.common.collect.ImmutableList;
 import com.google.common.primitives.UnsignedLong;
-import java.io.Serial;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.util.Collection;
 import java.util.List;
 import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.controller.cluster.access.ABIVersion;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
+import org.opendaylight.yangtools.concepts.WritableObjects;
 
 /**
  * Request to skip a number of {@link TransactionIdentifier}s within a {code local history}. This request is essentially
@@ -28,7 +31,50 @@ import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier
  * explicitly retired and are guaranteed to never be used by the frontend.
  */
 public final class SkipTransactionsRequest extends TransactionRequest<SkipTransactionsRequest> {
-    @Serial
+    interface SerialForm extends TransactionRequest.SerialForm<SkipTransactionsRequest> {
+        @Override
+        default SkipTransactionsRequest readExternal(final ObjectInput in, final TransactionIdentifier target,
+                final long sequence, final ActorRef replyTo) throws IOException {
+            final int size = in.readInt();
+            final var builder = ImmutableList.<UnsignedLong>builderWithExpectedSize(size);
+            int idx;
+            if (size % 2 != 0) {
+                builder.add(UnsignedLong.fromLongBits(WritableObjects.readLong(in)));
+                idx = 1;
+            } else {
+                idx = 0;
+            }
+            for (; idx < size; idx += 2) {
+                final byte hdr = WritableObjects.readLongHeader(in);
+                builder.add(UnsignedLong.fromLongBits(WritableObjects.readFirstLong(in, hdr)));
+                builder.add(UnsignedLong.fromLongBits(WritableObjects.readSecondLong(in, hdr)));
+            }
+
+            return new SkipTransactionsRequest(target, sequence, replyTo, builder.build());
+        }
+
+        @Override
+        default void writeExternal(final ObjectOutput out, final SkipTransactionsRequest msg) throws IOException {
+            TransactionRequest.SerialForm.super.writeExternal(out, msg);
+
+            final var others = msg.others;
+            final int size = others.size();
+            out.writeInt(size);
+
+            int idx;
+            if (size % 2 != 0) {
+                WritableObjects.writeLong(out, others.get(0).longValue());
+                idx = 1;
+            } else {
+                idx = 0;
+            }
+            for (; idx < size; idx += 2) {
+                WritableObjects.writeLongs(out, others.get(idx).longValue(), others.get(idx + 1).longValue());
+            }
+        }
+    }
+
+    @java.io.Serial
     private static final long serialVersionUID = 1L;
 
     // Note: UnsignedLong is arbitrary, yang.common.Uint64 would work just as well, we really want an immutable
@@ -41,6 +87,11 @@ public final class SkipTransactionsRequest extends TransactionRequest<SkipTransa
         this.others = ImmutableList.copyOf(others);
     }
 
+    private SkipTransactionsRequest(final SkipTransactionsRequest request, final ABIVersion version) {
+        super(request, version);
+        others = request.others;
+    }
+
     /**
      * Return this {@link #getTarget()}s sibling {@link TransactionIdentifier}s.
      *
@@ -51,13 +102,13 @@ public final class SkipTransactionsRequest extends TransactionRequest<SkipTransa
     }
 
     @Override
-    protected SkipTransactionsRequestV1 externalizableProxy(final ABIVersion version) {
-        return new SkipTransactionsRequestV1(this);
+    protected SerialForm externalizableProxy(final ABIVersion version) {
+        return ABIVersion.MAGNESIUM.lt(version) ? new STR(this) : new SkipTransactionsRequestV1(this);
     }
 
     @Override
     protected SkipTransactionsRequest cloneAsVersion(final ABIVersion version) {
-        return this;
+        return new SkipTransactionsRequest(this, version);
     }
 
     @Override