Commit | Line | Data |
---|---|---|
8e15b929 MK |
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 | ||
9bc60be7 | 14 | package org.eclipse.tracecompass.internal.lttng2.control.core.relayd.lttngviewerCommands; |
8e15b929 MK |
15 | |
16 | import java.nio.ByteBuffer; | |
17 | import java.nio.ByteOrder; | |
18 | ||
19 | /** | |
20 | * VIEWER_GET_PACKET payload. | |
21 | * | |
22 | * @author Matthew Khouzam | |
8e15b929 MK |
23 | */ |
24 | public class GetPacket implements IRelayCommand { | |
25 | ||
26 | /** | |
27 | * Command size | |
8adfbb73 MAL |
28 | * |
29 | * fStreamId + fOffset + fLength | |
8e15b929 MK |
30 | */ |
31 | public static final int SIZE = (Long.SIZE + Long.SIZE + Integer.SIZE) / 8; | |
32 | /** the stream Id */ | |
33 | private final long fStreamId; | |
34 | /** the offset */ | |
35 | private final long fOffset; | |
36 | /** the length of the packet */ | |
37 | private final int fLength; | |
38 | ||
39 | /** | |
40 | * Get packet constructor | |
41 | * | |
42 | * @param streamId | |
43 | * the stream id | |
44 | * @param offset | |
45 | * the offset | |
46 | * @param length | |
47 | * the packet length | |
48 | */ | |
49 | public GetPacket(long streamId, long offset, int length) { | |
50 | fStreamId = streamId; | |
51 | fOffset = offset; | |
52 | fLength = length; | |
53 | } | |
54 | ||
55 | /** | |
56 | * Get the length of the packet | |
57 | * | |
58 | * @return the length of the packet in bytes | |
59 | */ | |
60 | public int getLength() { | |
61 | return fLength; | |
62 | } | |
63 | ||
64 | /** | |
65 | * Gets the offset of the packet | |
66 | * | |
67 | * @return the offset | |
68 | */ | |
69 | public long getOffset() { | |
70 | return fOffset; | |
71 | } | |
72 | ||
73 | /** | |
74 | * Gets the stream id | |
75 | * | |
76 | * @return the stream id | |
77 | */ | |
78 | public long getStreamId() { | |
79 | return fStreamId; | |
80 | } | |
81 | ||
82 | @Override | |
83 | public byte[] serialize() { | |
84 | byte data[] = new byte[SIZE]; | |
85 | ByteBuffer bb = ByteBuffer.wrap(data); | |
86 | bb.order(ByteOrder.BIG_ENDIAN); | |
87 | bb.putLong(getStreamId()); | |
88 | bb.putLong(getOffset()); | |
89 | bb.putInt(getLength()); | |
90 | return data; | |
91 | } | |
92 | ||
93 | } |