2 * Copyright (c) 2022 PANTHEON.tech, s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.controller.cluster.raft.persisted;
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;
18 * Serialization proxy for {@link SimpleReplicatedLogEntry}.
20 final class LE implements Externalizable {
22 private static final long serialVersionUID = 1L;
28 @SuppressWarnings("checkstyle:RedundantModifier")
33 // For size estimation only, use full bit size
34 LE(final Void dummy) {
35 index = Long.MIN_VALUE;
36 term = Long.MIN_VALUE;
40 LE(final SimpleReplicatedLogEntry logEntry) {
41 index = logEntry.getIndex();
42 term = logEntry.getTerm();
43 data = logEntry.getData();
47 public void writeExternal(final ObjectOutput out) throws IOException {
48 WritableObjects.writeLongs(out, index, term);
49 out.writeObject(data);
53 public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
54 final byte hdr = WritableObjects.readLongHeader(in);
55 index = WritableObjects.readFirstLong(in, hdr);
56 term = WritableObjects.readSecondLong(in, hdr);
57 data = (Payload) in.readObject();
61 private Object readResolve() {
62 return new SimpleReplicatedLogEntry(index, term, data);