1 /**
2 Abstraction and base class for stream-based protocols.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.streampeer;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.meta;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.object;
22 import godot.reference;
23 /**
24 Abstraction and base class for stream-based protocols.
25 
26 StreamPeer is an abstraction and base class for stream-based protocols (such as TCP or Unix Sockets). It provides an API for sending and receiving data through streams as raw data or strings.
27 */
28 @GodotBaseClass struct StreamPeer
29 {
30 	enum string _GODOT_internal_name = "StreamPeer";
31 public:
32 @nogc nothrow:
33 	union { godot_object _godot_object; Reference _GODOT_base; }
34 	alias _GODOT_base this;
35 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
36 	package(godot) __gshared bool _classBindingInitialized = false;
37 	package(godot) static struct _classBinding
38 	{
39 		__gshared:
40 		@GodotName("put_data") GodotMethod!(GodotError, PoolByteArray) putData;
41 		@GodotName("put_partial_data") GodotMethod!(Array, PoolByteArray) putPartialData;
42 		@GodotName("get_data") GodotMethod!(Array, long) getData;
43 		@GodotName("get_partial_data") GodotMethod!(Array, long) getPartialData;
44 		@GodotName("get_available_bytes") GodotMethod!(long) getAvailableBytes;
45 		@GodotName("set_big_endian") GodotMethod!(void, bool) setBigEndian;
46 		@GodotName("is_big_endian_enabled") GodotMethod!(bool) isBigEndianEnabled;
47 		@GodotName("put_8") GodotMethod!(void, long) put8;
48 		@GodotName("put_u8") GodotMethod!(void, long) putU8;
49 		@GodotName("put_16") GodotMethod!(void, long) put16;
50 		@GodotName("put_u16") GodotMethod!(void, long) putU16;
51 		@GodotName("put_32") GodotMethod!(void, long) put32;
52 		@GodotName("put_u32") GodotMethod!(void, long) putU32;
53 		@GodotName("put_64") GodotMethod!(void, long) put64;
54 		@GodotName("put_u64") GodotMethod!(void, long) putU64;
55 		@GodotName("put_float") GodotMethod!(void, double) putFloat;
56 		@GodotName("put_double") GodotMethod!(void, double) putDouble;
57 		@GodotName("put_string") GodotMethod!(void, String) putString;
58 		@GodotName("put_utf8_string") GodotMethod!(void, String) putUtf8String;
59 		@GodotName("put_var") GodotMethod!(void, Variant) putVar;
60 		@GodotName("get_8") GodotMethod!(long) get8;
61 		@GodotName("get_u8") GodotMethod!(long) getU8;
62 		@GodotName("get_16") GodotMethod!(long) get16;
63 		@GodotName("get_u16") GodotMethod!(long) getU16;
64 		@GodotName("get_32") GodotMethod!(long) get32;
65 		@GodotName("get_u32") GodotMethod!(long) getU32;
66 		@GodotName("get_64") GodotMethod!(long) get64;
67 		@GodotName("get_u64") GodotMethod!(long) getU64;
68 		@GodotName("get_float") GodotMethod!(double) getFloat;
69 		@GodotName("get_double") GodotMethod!(double) getDouble;
70 		@GodotName("get_string") GodotMethod!(String, long) getString;
71 		@GodotName("get_utf8_string") GodotMethod!(String, long) getUtf8String;
72 		@GodotName("get_var") GodotMethod!(Variant) getVar;
73 	}
74 	bool opEquals(in StreamPeer other) const { return _godot_object.ptr is other._godot_object.ptr; }
75 	StreamPeer opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; }
76 	bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; }
77 	mixin baseCasts;
78 	static StreamPeer _new()
79 	{
80 		static godot_class_constructor constructor;
81 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("StreamPeer");
82 		if(constructor is null) return typeof(this).init;
83 		return cast(StreamPeer)(constructor());
84 	}
85 	@disable new(size_t s);
86 	/**
87 	Send a chunk of data through the connection, blocking if necessary until the data is done sending. This function returns an Error code.
88 	*/
89 	GodotError putData(in PoolByteArray data)
90 	{
91 		checkClassBinding!(typeof(this))();
92 		return ptrcall!(GodotError)(_classBinding.putData, _godot_object, data);
93 	}
94 	/**
95 	Send a chunk of data through the connection, if all the data could not be sent at once, only part of it will. This function returns two values, an Error code and an integer, describing how much data was actually sent.
96 	*/
97 	Array putPartialData(in PoolByteArray data)
98 	{
99 		checkClassBinding!(typeof(this))();
100 		return ptrcall!(Array)(_classBinding.putPartialData, _godot_object, data);
101 	}
102 	/**
103 	Return a chunk data with the received bytes. The amount of bytes to be received can be requested in the "bytes" argument. If not enough bytes are available, the function will block until the desired amount is received. This function returns two values, an Error code and a data array.
104 	*/
105 	Array getData(in long bytes)
106 	{
107 		checkClassBinding!(typeof(this))();
108 		return ptrcall!(Array)(_classBinding.getData, _godot_object, bytes);
109 	}
110 	/**
111 	Return a chunk data with the received bytes. The amount of bytes to be received can be requested in the "bytes" argument. If not enough bytes are available, the function will return how many were actually received. This function returns two values, an Error code, and a data array.
112 	*/
113 	Array getPartialData(in long bytes)
114 	{
115 		checkClassBinding!(typeof(this))();
116 		return ptrcall!(Array)(_classBinding.getPartialData, _godot_object, bytes);
117 	}
118 	/**
119 	Return the amount of bytes this `StreamPeer` has available.
120 	*/
121 	long getAvailableBytes() const
122 	{
123 		checkClassBinding!(typeof(this))();
124 		return ptrcall!(long)(_classBinding.getAvailableBytes, _godot_object);
125 	}
126 	/**
127 	
128 	*/
129 	void setBigEndian(in bool enable)
130 	{
131 		checkClassBinding!(typeof(this))();
132 		ptrcall!(void)(_classBinding.setBigEndian, _godot_object, enable);
133 	}
134 	/**
135 	
136 	*/
137 	bool isBigEndianEnabled() const
138 	{
139 		checkClassBinding!(typeof(this))();
140 		return ptrcall!(bool)(_classBinding.isBigEndianEnabled, _godot_object);
141 	}
142 	/**
143 	Put a signed byte into the stream.
144 	*/
145 	void put8(in long value)
146 	{
147 		checkClassBinding!(typeof(this))();
148 		ptrcall!(void)(_classBinding.put8, _godot_object, value);
149 	}
150 	/**
151 	Put an unsigned byte into the stream.
152 	*/
153 	void putU8(in long value)
154 	{
155 		checkClassBinding!(typeof(this))();
156 		ptrcall!(void)(_classBinding.putU8, _godot_object, value);
157 	}
158 	/**
159 	Put a signed 16 bit value into the stream.
160 	*/
161 	void put16(in long value)
162 	{
163 		checkClassBinding!(typeof(this))();
164 		ptrcall!(void)(_classBinding.put16, _godot_object, value);
165 	}
166 	/**
167 	Put an unsigned 16 bit value into the stream.
168 	*/
169 	void putU16(in long value)
170 	{
171 		checkClassBinding!(typeof(this))();
172 		ptrcall!(void)(_classBinding.putU16, _godot_object, value);
173 	}
174 	/**
175 	Put a signed 32 bit value into the stream.
176 	*/
177 	void put32(in long value)
178 	{
179 		checkClassBinding!(typeof(this))();
180 		ptrcall!(void)(_classBinding.put32, _godot_object, value);
181 	}
182 	/**
183 	Put an unsigned 32 bit value into the stream.
184 	*/
185 	void putU32(in long value)
186 	{
187 		checkClassBinding!(typeof(this))();
188 		ptrcall!(void)(_classBinding.putU32, _godot_object, value);
189 	}
190 	/**
191 	Put a signed 64 bit value into the stream.
192 	*/
193 	void put64(in long value)
194 	{
195 		checkClassBinding!(typeof(this))();
196 		ptrcall!(void)(_classBinding.put64, _godot_object, value);
197 	}
198 	/**
199 	Put an unsigned 64 bit value into the stream.
200 	*/
201 	void putU64(in long value)
202 	{
203 		checkClassBinding!(typeof(this))();
204 		ptrcall!(void)(_classBinding.putU64, _godot_object, value);
205 	}
206 	/**
207 	Put a single-precision float into the stream.
208 	*/
209 	void putFloat(in double value)
210 	{
211 		checkClassBinding!(typeof(this))();
212 		ptrcall!(void)(_classBinding.putFloat, _godot_object, value);
213 	}
214 	/**
215 	Put a double-precision float into the stream.
216 	*/
217 	void putDouble(in double value)
218 	{
219 		checkClassBinding!(typeof(this))();
220 		ptrcall!(void)(_classBinding.putDouble, _godot_object, value);
221 	}
222 	/**
223 	Put a zero-terminated ascii string into the stream prepended by a 32 bits unsigned integer representing its size.
224 	*/
225 	void putString(StringArg0)(in StringArg0 value)
226 	{
227 		checkClassBinding!(typeof(this))();
228 		ptrcall!(void)(_classBinding.putString, _godot_object, value);
229 	}
230 	/**
231 	Put a zero-terminated utf8 string into the stream prepended by a 32 bits unsigned integer representing its size.
232 	*/
233 	void putUtf8String(StringArg0)(in StringArg0 value)
234 	{
235 		checkClassBinding!(typeof(this))();
236 		ptrcall!(void)(_classBinding.putUtf8String, _godot_object, value);
237 	}
238 	/**
239 	Put a Variant into the stream.
240 	*/
241 	void putVar(VariantArg0)(in VariantArg0 value)
242 	{
243 		checkClassBinding!(typeof(this))();
244 		ptrcall!(void)(_classBinding.putVar, _godot_object, value);
245 	}
246 	/**
247 	Get a signed byte from the stream.
248 	*/
249 	long get8()
250 	{
251 		checkClassBinding!(typeof(this))();
252 		return ptrcall!(long)(_classBinding.get8, _godot_object);
253 	}
254 	/**
255 	Get an unsigned byte from the stream.
256 	*/
257 	long getU8()
258 	{
259 		checkClassBinding!(typeof(this))();
260 		return ptrcall!(long)(_classBinding.getU8, _godot_object);
261 	}
262 	/**
263 	Get a signed 16 bit value from the stream.
264 	*/
265 	long get16()
266 	{
267 		checkClassBinding!(typeof(this))();
268 		return ptrcall!(long)(_classBinding.get16, _godot_object);
269 	}
270 	/**
271 	Get an unsigned 16 bit value from the stream.
272 	*/
273 	long getU16()
274 	{
275 		checkClassBinding!(typeof(this))();
276 		return ptrcall!(long)(_classBinding.getU16, _godot_object);
277 	}
278 	/**
279 	Get a signed 32 bit value from the stream.
280 	*/
281 	long get32()
282 	{
283 		checkClassBinding!(typeof(this))();
284 		return ptrcall!(long)(_classBinding.get32, _godot_object);
285 	}
286 	/**
287 	Get an unsigned 32 bit value from the stream.
288 	*/
289 	long getU32()
290 	{
291 		checkClassBinding!(typeof(this))();
292 		return ptrcall!(long)(_classBinding.getU32, _godot_object);
293 	}
294 	/**
295 	Get a signed 64 bit value from the stream.
296 	*/
297 	long get64()
298 	{
299 		checkClassBinding!(typeof(this))();
300 		return ptrcall!(long)(_classBinding.get64, _godot_object);
301 	}
302 	/**
303 	Get an unsigned 64 bit value from the stream.
304 	*/
305 	long getU64()
306 	{
307 		checkClassBinding!(typeof(this))();
308 		return ptrcall!(long)(_classBinding.getU64, _godot_object);
309 	}
310 	/**
311 	Get a single-precision float from the stream.
312 	*/
313 	double getFloat()
314 	{
315 		checkClassBinding!(typeof(this))();
316 		return ptrcall!(double)(_classBinding.getFloat, _godot_object);
317 	}
318 	/**
319 	Get a double-precision float from the stream.
320 	*/
321 	double getDouble()
322 	{
323 		checkClassBinding!(typeof(this))();
324 		return ptrcall!(double)(_classBinding.getDouble, _godot_object);
325 	}
326 	/**
327 	Get a string with byte-length `bytes` from the stream. If `bytes` is negative (default) the length will be read from the stream using the reverse process of $(D putString).
328 	*/
329 	String getString(in long bytes = -1)
330 	{
331 		checkClassBinding!(typeof(this))();
332 		return ptrcall!(String)(_classBinding.getString, _godot_object, bytes);
333 	}
334 	/**
335 	Get a utf8 string with byte-length `bytes` from the stream (this decodes the string sent as utf8). If `bytes` is negative (default) the length will be read from the stream using the reverse process of $(D putUtf8String).
336 	*/
337 	String getUtf8String(in long bytes = -1)
338 	{
339 		checkClassBinding!(typeof(this))();
340 		return ptrcall!(String)(_classBinding.getUtf8String, _godot_object, bytes);
341 	}
342 	/**
343 	Get a Variant from the stream.
344 	*/
345 	Variant getVar()
346 	{
347 		checkClassBinding!(typeof(this))();
348 		return ptrcall!(Variant)(_classBinding.getVar, _godot_object);
349 	}
350 	/**
351 	If `true`, this `StreamPeer` will using big-endian format for encoding and decoding.
352 	*/
353 	@property bool bigEndian()
354 	{
355 		return isBigEndianEnabled();
356 	}
357 	/// ditto
358 	@property void bigEndian(bool v)
359 	{
360 		setBigEndian(v);
361 	}
362 }