2 * Copyright (c) 2014, 2015 Cable Television Laboratories, 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
9 package org.pcmm.objects;
11 import org.pcmm.base.impl.PCMMBaseObject;
12 import org.umu.cops.stack.COPSMsgParser;
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
20 public class MMVersionInfo extends PCMMBaseObject {
22 public static final short DEFAULT_MAJOR_VERSION_INFO = (short) 5;
23 public static final short DEFAULT_MINOR_VERSION_INFO = (short) 0;
26 * The major version number
28 private final short majorVersionNB;
31 * The minor version number
33 private final short minorVersionNB;
37 * @param majorVersionNB - the major version number
38 * @param minorVersionNB - the minor version number
40 public MMVersionInfo(short majorVersionNB, short minorVersionNB) {
41 super(SNum.VERSION_INFO, (byte)1);
42 this.majorVersionNB = majorVersionNB;
43 this.minorVersionNB = minorVersionNB;
47 * @return the majorVersionNB
49 public short getMajorVersionNB() {
50 return majorVersionNB;
54 * @return the minorVersionNB
56 public short getMinorVersionNB() {
57 return minorVersionNB;
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);
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.
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]));