Bump to odlparent 3.1.0 and yangtools 2.0.3
[packetcable.git] / packetcable-driver / src / main / java / org / pcmm / objects / MMVersionInfo.java
1 /*
2  * Copyright (c) 2014, 2015 Cable Television Laboratories, 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
9 package org.pcmm.objects;
10
11 import org.pcmm.base.impl.PCMMBaseObject;
12 import org.umu.cops.stack.COPSMsgParser;
13
14 /**
15  * The Version Info object is used to enable Multimedia applications to adapt their interactions with other devices so
16  * that interoperability can be achieved between products supporting different protocol versions. Both the Major
17  * Version Number and the Minor Version Number are 2 byte unsigned integers. Both the PDP and the PEP must include this
18  * object as specified in Section 6.5.1
19  */
20 public class MMVersionInfo extends PCMMBaseObject {
21
22     public static final short DEFAULT_MAJOR_VERSION_INFO = (short) 5;
23     public static final short DEFAULT_MINOR_VERSION_INFO = (short) 0;
24
25     /**
26      * The major version number
27      */
28     private final short majorVersionNB;
29
30     /**
31      * The minor version number
32      */
33     private final short minorVersionNB;
34
35     /**
36      * Constructor
37      * @param majorVersionNB - the major version number
38      * @param minorVersionNB - the minor version number
39      */
40     public MMVersionInfo(short majorVersionNB, short minorVersionNB) {
41         super(SNum.VERSION_INFO, (byte)1);
42         this.majorVersionNB = majorVersionNB;
43         this.minorVersionNB = minorVersionNB;
44     }
45
46     /**
47      * @return the majorVersionNB
48      */
49     public short getMajorVersionNB() {
50         return majorVersionNB;
51     }
52
53     /**
54      * @return the minorVersionNB
55      */
56     public short getMinorVersionNB() {
57         return minorVersionNB;
58     }
59
60     @Override
61     protected byte[] getBytes() {
62         final byte[] majVerBytes = COPSMsgParser.shortToBytes(majorVersionNB);
63         final byte[] minVerBytes = COPSMsgParser.shortToBytes(minorVersionNB);
64         final byte[] data = new byte[majVerBytes.length + minVerBytes.length];
65         System.arraycopy(majVerBytes, 0, data, 0, majVerBytes.length);
66         System.arraycopy(minVerBytes, 0, data, majVerBytes.length, minVerBytes.length);
67         return data;
68     }
69
70     /**
71      * Returns an MMVersionInfo object from a byte array
72      * @param data - the data to parse
73      * @return - the object
74      * TODO - make me more robust as RuntimeExceptions can be thrown here.
75      */
76     public static MMVersionInfo parse(final byte[] data) {
77         return new MMVersionInfo(COPSMsgParser.bytesToShort(data[0], data[1]),
78                 COPSMsgParser.bytesToShort(data[2], data[3]));
79     }
80
81 }