forked from openlcb/OpenLCB_Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamInitiateReplyMessage.java
More file actions
74 lines (64 loc) · 2.28 KB
/
StreamInitiateReplyMessage.java
File metadata and controls
74 lines (64 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package org.openlcb;
// For annotations
import net.jcip.annotations.*;
import edu.umd.cs.findbugs.annotations.*;
/**
* Stream Initialization Reply message implementation
*
* @author Bob Jacobsen Copyright 2009
* @version $Revision$
*/
@Immutable
@ThreadSafe
public class StreamInitiateReplyMessage extends AddressedPayloadMessage {
public StreamInitiateReplyMessage(NodeID source, NodeID dest,
int flags, int bufferSize, byte sourceStreamID, byte destStreamID) {
super(source, dest, toPayload(flags, bufferSize, sourceStreamID, destStreamID));
this.flags = flags;
this.bufferSize = bufferSize;
this.sourceStreamID = sourceStreamID;
this.destStreamID = destStreamID;
}
int flags;
int bufferSize;
byte sourceStreamID;
byte destStreamID;
public int getBufferSize() { return bufferSize; }
public byte getDestinationStreamID() { return destStreamID; }
public byte getSourceStreamID() { return sourceStreamID; } //dph 20151229
static byte[] toPayload(int flags, int bufferSize, byte sourceStreamID, byte destStreamID) {
byte[] b = new byte[]{0, 0, 0, 0, sourceStreamID, destStreamID};
Utilities.HostToNetworkUint16(b, 2, flags);
Utilities.HostToNetworkUint16(b, 0, bufferSize);
return b;
}
/**
* Implement message-type-specific
* processing when this message
* is received by a node.
*<p>
* Default is to do nothing.
*/
@Override
public void applyTo(MessageDecoder decoder, Connection sender) {
decoder.handleStreamInitiateReply(this, sender);
}
public boolean equals(Object o) {
if (!super.equals(o)) return false;
StreamInitiateReplyMessage p = (StreamInitiateReplyMessage) o;
if (bufferSize != p.bufferSize) return false;
if (sourceStreamID != p.sourceStreamID) return false;
if (destStreamID != p.destStreamID) return false;
return super.equals(o);
}
public String toString() {
return super.toString()
+" SSID "+sourceStreamID
+" DSID "+destStreamID
+" bsize "+bufferSize;
}
@Override
public MessageTypeIdentifier getEMTI() {
return MessageTypeIdentifier.StreamInitiateReply;
}
}