| 1 | /* |
| 2 | * SPDX-License-Identifier: LGPL-2.1-only |
| 3 | * |
| 4 | * Copyright (C) 2015 EfficiOS Inc. |
| 5 | * Copyright (C) 2015 Alexandre Montplaisir <alexmonthy@efficios.com> |
| 6 | * Copyright (C) 2013 David Goulet <dgoulet@efficios.com> |
| 7 | */ |
| 8 | |
| 9 | package org.lttng.ust.agent.client; |
| 10 | |
| 11 | import java.nio.ByteBuffer; |
| 12 | import java.nio.ByteOrder; |
| 13 | |
| 14 | import org.lttng.ust.agent.client.SessiondCommand.CommandType; |
| 15 | |
| 16 | /** |
| 17 | * Header of session daemon commands. |
| 18 | * |
| 19 | * @author Alexandre Montplaisir |
| 20 | * @author David Goulet |
| 21 | */ |
| 22 | class SessiondCommandHeader { |
| 23 | |
| 24 | /** ABI size of command header. */ |
| 25 | public static final int HEADER_SIZE = 16; |
| 26 | |
| 27 | /** Payload size in bytes following this header. */ |
| 28 | private final long dataSize; |
| 29 | |
| 30 | /** Command type. */ |
| 31 | private final CommandType cmd; |
| 32 | |
| 33 | public SessiondCommandHeader(byte[] data) { |
| 34 | ByteBuffer buf = ByteBuffer.wrap(data); |
| 35 | buf.order(ByteOrder.BIG_ENDIAN); |
| 36 | |
| 37 | dataSize = buf.getLong(); |
| 38 | cmd = CommandType.values()[buf.getInt() - 1]; |
| 39 | buf.getInt(); // command version, currently unused |
| 40 | } |
| 41 | |
| 42 | public long getDataSize() { |
| 43 | return dataSize; |
| 44 | } |
| 45 | |
| 46 | public CommandType getCommandType() { |
| 47 | return cmd; |
| 48 | } |
| 49 | } |