Define RaftVersions.ARGON_VERSION
[controller.git] / opendaylight / md-sal / sal-akka-raft / src / main / java / org / opendaylight / controller / cluster / raft / persisted / LE.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.controller.cluster.raft.persisted;
9
10 import java.io.Externalizable;
11 import java.io.IOException;
12 import java.io.ObjectInput;
13 import java.io.ObjectOutput;
14 import org.opendaylight.controller.cluster.raft.messages.Payload;
15 import org.opendaylight.yangtools.concepts.WritableObjects;
16
17 /**
18  * Serialization proxy for {@link SimpleReplicatedLogEntry}.
19  */
20 final class LE implements Externalizable {
21     @java.io.Serial
22     private static final long serialVersionUID = 1L;
23
24     private long index;
25     private long term;
26     private Payload data;
27
28     @SuppressWarnings("checkstyle:RedundantModifier")
29     public LE() {
30         // For Externalizable
31     }
32
33     LE(final SimpleReplicatedLogEntry logEntry) {
34         index = logEntry.getIndex();
35         term = logEntry.getTerm();
36         data = logEntry.getData();
37     }
38
39     @Override
40     public void writeExternal(final ObjectOutput out) throws IOException {
41         WritableObjects.writeLongs(out, index, term);
42         out.writeObject(data);
43     }
44
45     @Override
46     public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
47         final byte hdr = WritableObjects.readLongHeader(in);
48         index = WritableObjects.readFirstLong(in, hdr);
49         term = WritableObjects.readSecondLong(in, hdr);
50         data = (Payload) in.readObject();
51     }
52
53     @java.io.Serial
54     private Object readResolve() {
55         return new SimpleReplicatedLogEntry(index, term, data);
56     }
57 }