Migrate lisp-proto implementation to IETF YANG model
[lispflowmapping.git] / mappingservice / lisp-proto / src / main / java / org / opendaylight / lispflowmapping / lisp / 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.lisp.serializer;
9
10 import java.nio.ByteBuffer;
11
12 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializer;
13 import org.opendaylight.lispflowmapping.lisp.serializer.address.LispAddressSerializerContext;
14 import org.opendaylight.lispflowmapping.lisp.util.ByteUtil;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.eid.container.Eid;
16
17 public class EidRecordSerializer {
18
19     private static final EidRecordSerializer INSTANCE = new EidRecordSerializer();
20
21     // Private constructor prevents instantiation from other classes
22     private EidRecordSerializer() {
23     }
24
25     public static EidRecordSerializer getInstance() {
26         return INSTANCE;
27     }
28
29     public Eid deserialize(ByteBuffer requestBuffer) {
30         /* byte reserved = */requestBuffer.get();
31         short maskLength = (short) (ByteUtil.getUnsignedByte(requestBuffer));
32         LispAddressSerializerContext ctx = new LispAddressSerializerContext(maskLength);
33         return LispAddressSerializer.getInstance().deserializeEid(requestBuffer, ctx);
34     }
35 }