Move integration tests to mdsal-it-parent
[lispflowmapping.git] / mappingservice / implementation / src / main / java / org / opendaylight / lispflowmapping / implementation / serializer / EidRecordSerializer.java
1 /*
2  * Copyright (c) 2014 Contextream, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.lispflowmapping.implementation.serializer;
9
10 import java.nio.ByteBuffer;
11
12 import org.opendaylight.lispflowmapping.implementation.serializer.address.LispAddressSerializer;
13 import org.opendaylight.lispflowmapping.implementation.util.ByteUtil;
14 import org.opendaylight.lispflowmapping.implementation.util.LispAFIConvertor;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.LispAFIAddress;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.eidrecords.EidRecord;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.control.plane.rev150314.eidrecords.EidRecordBuilder;
18
19 public class EidRecordSerializer {
20
21     private static final EidRecordSerializer INSTANCE = new EidRecordSerializer();
22
23     // Private constructor prevents instantiation from other classes
24     private EidRecordSerializer() {
25     }
26
27     public static EidRecordSerializer getInstance() {
28         return INSTANCE;
29     }
30
31     public EidRecord deserialize(ByteBuffer requestBuffer) {
32         /* byte reserved = */requestBuffer.get();
33         short maskLength = (short) (ByteUtil.getUnsignedByte(requestBuffer));
34         LispAFIAddress prefix = LispAddressSerializer.getInstance().deserialize(requestBuffer);
35         return new EidRecordBuilder().setLispAddressContainer(LispAFIConvertor.toContainer(prefix))
36                 .setMask(maskLength).build();
37     }
38 }