1 /*
2  * hunt-proton: AMQP Protocol library for D programming language.
3  *
4  * Copyright (C) 2018-2019 HuntLabs
5  *
6  * Website: https://www.huntlabs.net/
7  *
8  * Licensed under the Apache-2.0 License.
9  *
10  */
11 
12 
13 module hunt.proton.amqp.transport.Begin;
14 
15 import hunt.Object;
16 import hunt.proton.amqp.Binary;
17 import hunt.proton.amqp.Symbol;
18 import hunt.proton.amqp.UnsignedInteger;
19 import hunt.proton.amqp.UnsignedShort;
20 import hunt.proton.amqp.transport.FrameBody;
21 import hunt.logging;
22 import hunt.collection.Map;
23 import hunt.collection.LinkedHashMap;
24 import hunt.collection.List;
25 
26 
27 class Begin : FrameBody
28 {
29     private UnsignedShort _remoteChannel;
30     private UnsignedInteger _nextOutgoingId;
31     private UnsignedInteger _incomingWindow;
32     private UnsignedInteger _outgoingWindow;
33     private UnsignedInteger _handleMax ;
34     private List!Symbol _offeredCapabilities;
35     private List!Symbol _desiredCapabilities;
36     private Map!(Symbol,Object) _properties;
37 
38     this() {
39         _handleMax = UnsignedInteger.valueOf(0xffffffff);
40         _properties = null;
41     }
42 
43     this(Begin other)
44     {
45         this._remoteChannel = other._remoteChannel;
46         this._nextOutgoingId = other._nextOutgoingId;
47         this._incomingWindow = other._incomingWindow;
48         this._outgoingWindow = other._outgoingWindow;
49         this._handleMax = other._handleMax;
50         if (other._offeredCapabilities !is null) {
51             this._offeredCapabilities = other.getOfferedCapabilities();
52         }
53         if (other._desiredCapabilities !is null) {
54             this._desiredCapabilities = other.getDesiredCapabilities();
55         }
56         if (other._properties !is null) {
57             this._properties = new LinkedHashMap!(Symbol,Object)(other._properties);
58         }
59     }
60 
61     public UnsignedShort getRemoteChannel()
62     {
63         return _remoteChannel;
64     }
65 
66     public void setRemoteChannel(UnsignedShort remoteChannel)
67     {
68         _remoteChannel = remoteChannel;
69     }
70 
71     public UnsignedInteger getNextOutgoingId()
72     {
73         return _nextOutgoingId;
74     }
75 
76     public void setNextOutgoingId(UnsignedInteger nextOutgoingId)
77     {
78         if( nextOutgoingId is null )
79         {
80             logError("the next-outgoing-id field is mandatory");
81         }
82 
83         _nextOutgoingId = nextOutgoingId;
84     }
85 
86     public UnsignedInteger getIncomingWindow()
87     {
88         return _incomingWindow;
89     }
90 
91     public void setIncomingWindow(UnsignedInteger incomingWindow)
92     {
93         if( incomingWindow is null )
94         {
95             logError("the incoming-window field is mandatory");
96         }
97 
98         _incomingWindow = incomingWindow;
99     }
100 
101     public UnsignedInteger getOutgoingWindow()
102     {
103         return _outgoingWindow;
104     }
105 
106     public void setOutgoingWindow(UnsignedInteger outgoingWindow)
107     {
108         if( outgoingWindow is null )
109         {
110             logError("the outgoing-window field is mandatory");
111         }
112 
113         _outgoingWindow = outgoingWindow;
114     }
115 
116     public UnsignedInteger getHandleMax()
117     {
118         return _handleMax;
119     }
120 
121     public void setHandleMax(UnsignedInteger handleMax)
122     {
123         _handleMax = handleMax;
124     }
125 
126     public List!Symbol getOfferedCapabilities()
127     {
128         return _offeredCapabilities;
129     }
130 
131     public void setOfferedCapabilities(List!Symbol offeredCapabilities)
132     {
133         _offeredCapabilities = offeredCapabilities;
134     }
135 
136     public List!Symbol getDesiredCapabilities()
137     {
138         return _desiredCapabilities;
139     }
140 
141     public void setDesiredCapabilities(List!Symbol desiredCapabilities)
142     {
143         _desiredCapabilities = desiredCapabilities;
144     }
145 
146     public Map!(Symbol,Object) getProperties()
147     {
148         return _properties;
149     }
150 
151     public void setProperties(Map!(Symbol,Object) properties)
152     {
153         _properties = properties;
154     }
155 
156     //override
157     public void invoke(E)(FrameBodyHandler!E handler, Binary payload, E context)
158     {
159         handler.handleBegin(this, payload, context);
160     }
161 
162     override string toString() {
163         // dfmt off
164         return "Begin{" ~
165                "remoteChannel=" ~ _remoteChannel.toString() ~
166                ", nextOutgoingId=" ~ _nextOutgoingId.toString() ~
167                ", incomingWindow=" ~ _incomingWindow.toString() ~
168                ", outgoingWindow=" ~ _outgoingWindow.toString() ~
169                ", handleMax=" ~ _handleMax.toString() ~
170                ", offeredCapabilities=" ~ (_offeredCapabilities is null ? "null" : _offeredCapabilities.toString()) ~
171                ", desiredCapabilities=" ~ (_desiredCapabilities is null ? "null" : _desiredCapabilities.toString()) ~
172                ", properties=" ~ (_properties is null ? "null" : _properties.toString()) ~
173                "}";
174         // dfmt on
175     }    
176 
177     public FrameBody copy()
178     {
179         return new Begin(this);
180     }
181 }