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.concepts;
10 import java.util.Collections;
13 import org.opendaylight.protocol.util.ByteArray;
14 import com.google.common.collect.Sets;
15 import com.google.common.primitives.UnsignedBytes;
17 public abstract class AbstractAddressFamily<T extends NetworkAddress<?>> implements AddressFamily<T> {
19 public Set<Prefix<T>> prefixListForBytes(byte[] bytes) {
20 if (bytes.length == 0)
21 return Collections.emptySet();
23 final Set<Prefix<T>> list = Sets.newHashSet();
25 while (byteOffset < bytes.length) {
26 final int bitLength = UnsignedBytes.toInt(ByteArray.subByte(bytes, byteOffset, 1)[0]);
28 final int byteCount = (bitLength % 8 != 0) ? (bitLength / 8) + 1 : bitLength / 8;
29 list.add(prefixForBytes(ByteArray.subByte(bytes, byteOffset, byteCount), bitLength));
30 byteOffset += byteCount;