package com.lumaserv.bgp.protocol; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; @Setter @Getter @NoArgsConstructor public class BGPPacket { Type type; byte[] message; public BGPPacket(byte[] packet) { type = Type.fromValue(packet[18]); message = new byte[packet.length-19]; System.arraycopy(packet, 19, message, 0, message.length); } public byte[] build() { byte[] packet = new byte[message.length + 19]; Arrays.fill(packet, 0, 16, (byte) 0xFF); packet[16] = (byte)(packet.length >> 8); packet[17] = (byte)(packet.length & 0xFF); packet[18] = type.getValue(); System.arraycopy(message, 0, packet, 19, message.length); return packet; } public static BGPPacket read(InputStream stream) throws IOException { byte[] packet = new byte[18]; int value; for(int i=0; i