2 * (c) 2015 Cable Television Laboratories, Inc. All rights reserved.
5 package org.pcmm.objects;
7 import org.pcmm.base.impl.PCMMBaseObject;
8 import org.umu.cops.stack.COPSMsgParser;
11 * The Version Info object is used to enable Multimedia applications to adapt their interactions with other devices so
12 * that interoperability can be achieved between products supporting different protocol versions. Both the Major
13 * Version Number and the Minor Version Number are 2 byte unsigned integers. Both the PDP and the PEP must include this
14 * object as specified in Section 6.5.1
16 public class MMVersionInfo extends PCMMBaseObject {
18 public static final short DEFAULT_MAJOR_VERSION_INFO = (short) 5;
19 public static final short DEFAULT_MINOR_VERSION_INFO = (short) 0;
22 * The major version number
24 private final short majorVersionNB;
27 * The minor version number
29 private final short minorVersionNB;
33 * @param majorVersionNB - the major version number
34 * @param minorVersionNB - the minor version number
36 public MMVersionInfo(short majorVersionNB, short minorVersionNB) {
37 super(SNum.VERSION_INFO, (byte)1);
38 this.majorVersionNB = majorVersionNB;
39 this.minorVersionNB = minorVersionNB;
43 * @return the majorVersionNB
45 public short getMajorVersionNB() {
46 return majorVersionNB;
50 * @return the minorVersionNB
52 public short getMinorVersionNB() {
53 return minorVersionNB;
57 protected byte[] getBytes() {
58 final byte[] majVerBytes = COPSMsgParser.shortToBytes(majorVersionNB);
59 final byte[] minVerBytes = COPSMsgParser.shortToBytes(minorVersionNB);
60 final byte[] data = new byte[majVerBytes.length + minVerBytes.length];
61 System.arraycopy(majVerBytes, 0, data, 0, majVerBytes.length);
62 System.arraycopy(minVerBytes, 0, data, majVerBytes.length, minVerBytes.length);
67 * Returns an MMVersionInfo object from a byte array
68 * @param data - the data to parse
69 * @return - the object
70 * TODO - make me more robust as RuntimeExceptions can be thrown here.
72 public static MMVersionInfo parse(final byte[] data) {
73 return new MMVersionInfo(COPSMsgParser.bytesToShort(data[0], data[1]),
74 COPSMsgParser.bytesToShort(data[2], data[3]));