001package jmri.jmrix.ipocs.protocol.packets;
002
003import java.nio.ByteBuffer;
004
005/**
006 * Packet transmitted as a response when requested by sender of a message and packet.
007 *
008 * @author Fredrik Elestedt Copyright (C) 2020
009 * @since 4.21.2
010 */
011@org.openide.util.lookup.ServiceProvider(service = Packet.class)
012public class AcknowledgementPacket extends Packet {
013  public final static byte IDENT = 4;
014  private short ackReason;
015
016  @Override
017  public byte getId() {
018    return IDENT;
019  }
020
021  @Override
022  protected void parseSpecific(ByteBuffer buffer) {
023    ackReason = buffer.getShort();
024  }
025
026  @Override
027  protected byte[] serializeSpecific() {
028    ByteBuffer buffer = ByteBuffer.allocate(2);
029    buffer.putShort(ackReason);
030    buffer.rewind();
031    return buffer.array();
032  }
033
034  public short getAckReason() {
035    return ackReason;
036  }
037
038  public void setAckReason(short ackReason) {
039    this.ackReason = ackReason;
040  }
041}