Remove unneed null checks
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.core / src / org / eclipse / tracecompass / internal / lttng2 / control / core / relayd / lttngviewerCommands / ViewerCommand.java
1 /**********************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial implementation and API
11 * Marc-Andre Laperle - Initial implementation and API
12 **********************************************************************/
13
14 package org.eclipse.tracecompass.internal.lttng2.control.core.relayd.lttngviewerCommands;
15
16 import java.nio.ByteBuffer;
17 import java.nio.ByteOrder;
18
19 /**
20 * The LTTng command
21 *
22 * @author Matthew Khouzam
23 */
24 public class ViewerCommand implements IRelayCommand {
25
26 /**
27 * Command size
28 *
29 * fDataSize + fCmdVersion + fCmd
30 */
31 public static final int SIZE = (Long.SIZE + Integer.SIZE) / 8 + Command.SIZE;
32 /**
33 * data size following this header, you normally attach a payload that one,
34 * in bytes
35 */
36 private final long fDataSize;
37 /** enum lttcomm_relayd_command */
38 private final Command fCmd;
39 /** command version */
40 private final int fCmdVersion;
41
42 /**
43 * Sets the packet command
44 *
45 * @param viewerConnect
46 * the command
47 * @param size size of the command
48 * @param version the version number
49 */
50 public ViewerCommand(Command viewerConnect, long size, int version) {
51 fCmd = viewerConnect;
52 fDataSize = size;
53 fCmdVersion = version;
54 }
55
56 /**
57 * Get the data size
58 *
59 * @return the DataSize
60 */
61 public long getDataSize() {
62 return fDataSize;
63 }
64
65 /**
66 * Get the command
67 *
68 * @return the Cmd
69 */
70 public Command getCmd() {
71 return fCmd;
72 }
73
74 /**
75 * Get the command version
76 *
77 * @return the CmdVersion
78 */
79 public int getCmdVersion() {
80 return fCmdVersion;
81 }
82
83 @Override
84 public byte[] serialize() {
85 byte data[] = new byte[SIZE];
86 ByteBuffer bb = ByteBuffer.wrap(data);
87 bb.order(ByteOrder.BIG_ENDIAN);
88 bb.putLong(getDataSize());
89 bb.putInt(getCmd().getCommand());
90 bb.putInt(fCmdVersion);
91 return data;
92 }
93
94
95 }
This page took 0.052626 seconds and 5 git commands to generate.