2 * Copyright (c) 2013 Cisco Systems, Inc. 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.protocol.pcep.impl.subobject;
10 import java.util.Arrays;
12 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
13 import org.opendaylight.protocol.pcep.subobject.RROAttributesSubobject;
15 public class RROAttributesSubobjectParser {
17 public static final int RES_F_LENGTH = 2;
19 public static final int RES_F_OFFSET = 0;
20 public static final int ATTRS_F_OFFSET = RES_F_OFFSET + RES_F_LENGTH;
22 public static RROAttributesSubobject parse(byte[] soContentsBytes) throws PCEPDeserializerException {
23 if (soContentsBytes == null || soContentsBytes.length == 0)
24 throw new IllegalArgumentException("Array of bytes is mandatory. Can't be null or empty.");
25 if (soContentsBytes.length <= RES_F_LENGTH)
26 throw new PCEPDeserializerException("Wrong length of array of bytes. Passed: " + soContentsBytes.length + "; Expected: >" + RES_F_LENGTH + ".");
28 final byte[] attributes = Arrays.copyOfRange(soContentsBytes, ATTRS_F_OFFSET, soContentsBytes.length);
30 return new RROAttributesSubobject(attributes);
33 public static byte[] put(RROAttributesSubobject objToSerialize) {
34 final byte[] retBytes = new byte[RES_F_LENGTH + objToSerialize.getAttributes().length];
36 final byte[] attrs = objToSerialize.getAttributes();
38 System.arraycopy(attrs, 0, retBytes, ATTRS_F_OFFSET, attrs.length);