001package jmri.jmrix.ipocs.protocol.packets;
002
003import java.nio.ByteBuffer;
004
005/**
006 * Sent as a response to a connection request.
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 ConnectionResponsePacket extends Packet {
013  public final static byte IDENT = 2;
014  private short protocolVersion;
015
016  @Override
017  public byte getId() {
018    return IDENT;
019  }
020
021  @Override
022  protected byte[] serializeSpecific() {
023    ByteBuffer buffer = ByteBuffer.allocate(2);
024    buffer.putShort(protocolVersion);
025    buffer.rewind();
026    return buffer.array();
027  }
028
029  @Override
030  protected void parseSpecific(ByteBuffer buffer) {
031    protocolVersion = buffer.getShort();
032  }
033
034  public short getProtocolVersion() {
035    return protocolVersion;
036  }
037
038  public void setProtocolVersion(short protocolVersion) {
039    this.protocolVersion = protocolVersion;
040  }
041}