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.messages;
10 import static com.google.common.base.Verify.verifyNotNull;
11 import static java.util.Objects.requireNonNull;
13 import java.io.Externalizable;
14 import java.io.IOException;
15 import java.io.ObjectInput;
16 import java.io.ObjectOutput;
17 import org.opendaylight.yangtools.concepts.WritableObjects;
20 * Serialization proxy for {@link RequestVoteReply}.
22 final class VR implements Externalizable {
24 private static final long serialVersionUID = 1L;
27 private static final int VOTE_GRANTED = 0x10;
29 private RequestVoteReply requestVoteReply;
31 @SuppressWarnings("checkstyle:RedundantModifier")
36 VR(final RequestVoteReply requestVoteReply) {
37 this.requestVoteReply = requireNonNull(requestVoteReply);
41 public void writeExternal(final ObjectOutput out) throws IOException {
42 WritableObjects.writeLong(out, requestVoteReply.getTerm(), requestVoteReply.isVoteGranted() ? VOTE_GRANTED : 0);
46 public void readExternal(final ObjectInput in) throws IOException {
47 final byte hdr = WritableObjects.readLongHeader(in);
48 requestVoteReply = new RequestVoteReply(WritableObjects.readLongBody(in, hdr),
49 (WritableObjects.longHeaderFlags(hdr) & VOTE_GRANTED) != 0);
53 private Object readResolve() {
54 return verifyNotNull(requestVoteReply);