2 * Copyright (c) 2014 Contextream, 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.lispflowmapping.implementation.serializer.address;
10 import java.nio.ByteBuffer;
12 import org.opendaylight.lispflowmapping.type.AddressFamilyNumberEnum;
13 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispAFIAddress;
14 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.LispDistinguishedNameAddress;
15 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.lispaddresscontainer.address.DistinguishedNameBuilder;
17 public class LispDistinguishedNameAddressSerializer extends LispAddressSerializer {
19 private static final LispDistinguishedNameAddressSerializer INSTANCE = new LispDistinguishedNameAddressSerializer();
21 // Private constructor prevents instantiation from other classes
22 private LispDistinguishedNameAddressSerializer() {
25 public static LispDistinguishedNameAddressSerializer getInstance() {
30 public int getAddressSize(LispAFIAddress lispAddress) {
31 return ((LispDistinguishedNameAddress) lispAddress).getDistinguishedName().length() + 1;
36 protected LispDistinguishedNameAddress deserializeData(ByteBuffer buffer) {
37 StringBuilder sb = new StringBuilder();
38 byte b = buffer.get();
43 return new DistinguishedNameBuilder().setAfi(AddressFamilyNumberEnum.DISTINGUISHED_NAME.getIanaCode()).setDistinguishedName((sb.toString()))
48 protected void serializeData(ByteBuffer buffer, LispAFIAddress lispAddress) {
49 LispDistinguishedNameAddress distinguishedNameAddress = (LispDistinguishedNameAddress) lispAddress;
50 buffer.put(distinguishedNameAddress.getDistinguishedName().getBytes());