+ fillParams(ByteArray.subByte(body, MIN_MSG_LENGTH, optLength), optParams);
+ }
+ logger.trace("Open message was parsed: AS = {}, holdTimer = {}, bgpId = {}, optParams = {}", as, holdTime, bgpId, optParams);
+ return new OpenBuilder().setMyAsNumber(as.getValue().intValue()).setHoldTimer((int) holdTime).setBgpIdentifier(bgpId).setBgpParameters(
+ optParams).build();
+ }
+
+ private void fillParams(final byte[] bytes, final List<BgpParameters> params) throws BGPDocumentedException {
+ if (bytes == null || bytes.length == 0) {
+ throw new IllegalArgumentException("Byte array cannot be null or empty.");
+ }
+
+ logger.trace("Started parsing of BGP parameter: {}", Arrays.toString(bytes));
+ int byteOffset = 0;
+ while (byteOffset < bytes.length) {
+ if (byteOffset + 2 >= bytes.length) {
+ // FIXME: throw a BGPDocumentedException here?
+ throw new IllegalArgumentException("Malformed parameter encountered (" + (bytes.length - byteOffset) + " bytes left)");
+ }
+
+ final int paramType = UnsignedBytes.toInt(bytes[byteOffset++]);
+ final int paramLength = UnsignedBytes.toInt(bytes[byteOffset++]);
+ final byte[] paramBody = ByteArray.subByte(bytes, byteOffset, paramLength);
+ byteOffset += paramLength;
+
+ final BgpParameters param;