cat-dev 0.0.13

A library for interacting with the CAT-DEV hardware units distributed by Nintendo (i.e. a type of Wii-U DevKits).
Documentation
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
//! Common models for all L4 Services.
//!
//! This mostly includes the [`Request`], and [`Response`] structures that
//! services are actively passed, and expected to return.

use crate::{
	errors::CatBridgeError,
	net::{Extensions, errors::CommonNetAPIError},
};
use bytes::{Bytes, BytesMut};
use fnv::FnvHasher;
use futures::Future;
use std::{
	fmt::{Debug, Formatter, Result as FmtResult},
	hash::{Hash, Hasher},
	marker::Send,
	net::SocketAddr,
};
use valuable::{Fields, NamedField, NamedValues, StructDef, Structable, Valuable, Value, Visit};

#[cfg(feature = "servers")]
use crate::{errors::NetworkError, net::errors::CommonNetNetworkError};
#[cfg(feature = "servers")]
use std::sync::Arc;
#[cfg(feature = "servers")]
use tokio::{io::AsyncReadExt, net::TcpStream, sync::Mutex};
#[cfg(feature = "servers")]
use tracing::error;

/// Used to do reference-to-value conversions thus not consuming the input value.
///
/// This is mainly used with state's to extract "substates" from a reference to main application
/// state.
pub trait FromRef<InputTy> {
	/// Converts to this type from a reference to the input type.
	fn from_ref(input: &InputTy) -> Self;
}

impl<InnerTy> FromRef<InnerTy> for InnerTy
where
	InnerTy: Clone,
{
	fn from_ref(input: &InnerTy) -> Self {
		input.clone()
	}
}

/// A request that came from either a TCP/UDP source.
pub struct Request<State: Clone + Send + Sync + 'static> {
	/// The actual body of the the underlying request.
	body: Bytes,
	/// Extensions that can in particular be attached to this request.
	ext: Extensions,
	/// The source address of where the request came from.
	source_address: SocketAddr,
	/// The active state for this request.
	state: State,
	/// The stream ID this request came in on.
	stream_id: Option<u64>,
	/// Indicate that the response needs to read a certain size, ignoring
	/// whatever the current NAGLE algorithim says.
	///
	/// This will still call 'post nagle hook', 'trace io', and will still
	/// obey NAGLE timeouts. It just overrides the _kind_ of NAGLE we do.
	#[cfg_attr(docsrs, doc(cfg(feature = "clients")))]
	#[cfg(feature = "clients")]
	explicit_read_amount: Option<usize>,
	/// Allow accessing the raw underlying stream while processing the request.
	#[cfg_attr(docsrs, doc(cfg(feature = "servers")))]
	#[cfg(feature = "servers")]
	#[allow(
		// TODO(mythra): refactor to type.
		clippy::type_complexity,
	)]
	stream_access: Option<Arc<Mutex<Option<(Option<BytesMut>, TcpStream)>>>>,
}

impl<State: Clone + Send + Sync + 'static> Request<State>
where
	State: Default,
{
	#[must_use]
	pub fn new(body: Bytes, source_address: SocketAddr, stream_id: Option<u64>) -> Self {
		Self {
			body,
			ext: Extensions::new(),
			source_address,
			state: Default::default(),
			stream_id,
			#[cfg(feature = "clients")]
			explicit_read_amount: None,
			#[cfg(feature = "servers")]
			stream_access: None,
		}
	}
}

impl<State: Clone + Send + Sync + 'static> Request<State> {
	#[must_use]
	pub fn new_with_state(
		body: Bytes,
		source_address: SocketAddr,
		state: State,
		stream_id: Option<u64>,
	) -> Self {
		Self {
			body,
			ext: Extensions::new(),
			source_address,
			state,
			stream_id,
			#[cfg(feature = "clients")]
			explicit_read_amount: None,
			#[cfg(feature = "servers")]
			stream_access: None,
		}
	}

	#[cfg_attr(docsrs, doc(cfg(feature = "clients")))]
	#[cfg(feature = "clients")]
	#[must_use]
	pub fn new_with_state_and_read_amount(
		body: Bytes,
		source_address: SocketAddr,
		state: State,
		stream_id: Option<u64>,
		explicit_read_amount: usize,
	) -> Self {
		Self {
			body,
			ext: Extensions::new(),
			source_address,
			state,
			stream_id,
			explicit_read_amount: Some(explicit_read_amount),
			#[cfg(feature = "servers")]
			stream_access: None,
		}
	}

	#[cfg_attr(docsrs, doc(cfg(feature = "servers")))]
	#[cfg(feature = "servers")]
	#[allow(
		// TODO(mythra): refactor to type.
		clippy::type_complexity,
	)]
	#[must_use]
	pub fn new_with_state_and_stream(
		body: Bytes,
		source_address: SocketAddr,
		state: State,
		stream_id: Option<u64>,
		stream_and_nagle_cache: Arc<Mutex<Option<(Option<BytesMut>, TcpStream)>>>,
	) -> Self {
		Self {
			body,
			ext: Extensions::new(),
			source_address,
			state,
			stream_id,
			#[cfg(feature = "clients")]
			explicit_read_amount: None,
			stream_access: Some(stream_and_nagle_cache),
		}
	}

	/// Swap the body of the request to something new.
	pub fn swap_body(&mut self, new_body: Bytes) {
		self.body = new_body;
	}

	/// Update the core request source.
	pub const fn update_request_source(&mut self, source: SocketAddr, stream_id: Option<u64>) {
		self.source_address = source;
		self.stream_id = stream_id;
	}

	/// A unique identifier for the "stream" or connection of a packet.
	///
	/// In UDP which doesn't have stream this uses the source address as
	/// the core identifier.
	#[must_use]
	pub fn stream_id(&self) -> u64 {
		if let Some(id) = self.stream_id {
			id
		} else {
			let mut hasher = FnvHasher::default();
			self.source_address.hash(&mut hasher);
			hasher.finish()
		}
	}

	/// A client has requested we send this request, and then read an explicit
	/// amount of bytes, ignoring whatever the current NAGLE method is.
	///
	/// This is a utility only available when we are a client, and are receiving
	/// a packet that changes what our nagle split is for it's specific response
	/// while keeping the nagle the same otherwise.
	#[cfg_attr(docsrs, doc(cfg(feature = "clients")))]
	#[cfg(feature = "clients")]
	#[must_use]
	pub const fn explicit_read_amount(&self) -> Option<usize> {
		self.explicit_read_amount
	}

	/// Override the current NAGLE algorithm being used by this client for this
	/// single request/response pair. Do a single non-nagle'd receive.
	#[cfg_attr(docsrs, doc(cfg(feature = "clients")))]
	#[cfg(feature = "clients")]
	pub const fn set_explicit_read_amount(&mut self, new_read_amount: usize) {
		self.explicit_read_amount = Some(new_read_amount);
	}

	/// Attempt to read more bytes from the TCP Stream directly.
	///
	/// This is a utility only available when we are a server, and need to request
	/// more info from the client.
	///
	/// ***THIS WILL BYPASS EVERYYTHING PROVIDED BY TCP SERVER, AND JUST READ RAW
	/// BYTES FROM THE STREAM.*** This is only for requests like File I/O which
	/// _need_ to bypass all the logic provided by the stream classes.
	///
	/// ## Errors
	///
	/// If the request has been moved outside of it's original processing place,
	/// and it is no longer possible to read from the stream.
	#[cfg_attr(docsrs, doc(cfg(feature = "servers")))]
	#[cfg(feature = "servers")]
	pub async fn unsafe_read_more_bytes_from_stream(
		&self,
		to_read: usize,
	) -> Result<Bytes, CatBridgeError> {
		if let Some(strm) = self.stream_access.as_ref() {
			let mut guard = strm.lock().await;

			if let Some((opt_cache, stream)) = guard.as_mut() {
				let mut buff = BytesMut::with_capacity(to_read);

				if let Some(cache) = opt_cache.as_mut() {
					if cache.len() <= to_read {
						buff = cache.split();
					} else {
						buff = cache.split_to(to_read);
					}
				}

				if buff.len() < to_read {
					stream.readable().await.map_err(NetworkError::IO)?;
					let mut needed = to_read - buff.len();
					while needed > 0 {
						let read = stream.read_buf(&mut buff).await.map_err(NetworkError::IO)?;
						needed -= read;
					}
				}
				return Ok::<Bytes, CatBridgeError>(buff.freeze());
			}
		}

		error!("called unsafe_read_more_bytes on a stream that is not processing!");
		Err(CommonNetNetworkError::StreamNoLongerProcessing.into())
	}

	#[must_use]
	pub const fn body(&self) -> &Bytes {
		&self.body
	}
	#[must_use]
	pub fn body_mut(&mut self) -> &mut Bytes {
		&mut self.body
	}
	pub fn set_body(&mut self, new_body: Bytes) {
		self.body = new_body;
	}
	#[must_use]
	pub fn body_owned(self) -> Bytes {
		self.body
	}

	#[must_use]
	pub const fn extensions(&self) -> &Extensions {
		&self.ext
	}
	#[must_use]
	pub fn extensions_mut(&mut self) -> &mut Extensions {
		&mut self.ext
	}
	#[must_use]
	pub fn extensions_owned(self) -> Extensions {
		self.ext
	}

	#[must_use]
	pub const fn state(&self) -> &State {
		&self.state
	}
	#[must_use]
	pub fn state_mut(&mut self) -> &mut State {
		&mut self.state
	}

	#[must_use]
	pub const fn source(&self) -> &SocketAddr {
		&self.source_address
	}
	#[must_use]
	pub fn is_ipv4(&self) -> bool {
		self.source_address.ip().is_ipv4()
	}
	#[must_use]
	pub fn is_ipv6(&self) -> bool {
		self.source_address.ip().is_ipv6()
	}
}

impl<State: Clone + Send + Sync + 'static> Clone for Request<State> {
	fn clone(&self) -> Self {
		Request {
			body: self.body.clone(),
			ext: Extensions::new(),
			source_address: self.source_address,
			state: self.state.clone(),
			stream_id: self.stream_id,
			#[cfg(feature = "clients")]
			explicit_read_amount: self.explicit_read_amount,
			#[cfg(feature = "servers")]
			stream_access: self.stream_access.clone(),
		}
	}
}

impl<State: Clone + Send + Sync + 'static> Debug for Request<State>
where
	State: Debug,
{
	fn fmt(&self, fmt: &mut Formatter<'_>) -> FmtResult {
		let mut dbg_struct = fmt.debug_struct("Request");

		dbg_struct
			.field("body", &self.body)
			// Extensions can't be printed in debug by hyper, and in order to keep
			// compatability ours don't.
			.field("source_address", &self.source_address)
			.field("stream_id", &self.stream_id);

		#[cfg(feature = "clients")]
		dbg_struct.field("explicit_read_amount", &self.explicit_read_amount);
		#[cfg(feature = "servers")]
		dbg_struct.field(
			"stream_access",
			&if self.stream_access.is_some() {
				"<stream>"
			} else {
				"<none>"
			},
		);

		dbg_struct.finish_non_exhaustive()
	}
}

const REQUEST_FIELDS: &[NamedField<'static>] = &[
	NamedField::new("body"),
	NamedField::new("source_address"),
	NamedField::new("stream_id"),
	#[cfg(feature = "clients")]
	NamedField::new("explicit_read_amount"),
	#[cfg(feature = "servers")]
	NamedField::new("stream_access"),
];

impl<State: Clone + Send + Sync + 'static> Structable for Request<State> {
	fn definition(&self) -> StructDef<'_> {
		StructDef::new_static("Request", Fields::Named(REQUEST_FIELDS))
	}
}

impl<State: Clone + Send + Sync + 'static> Valuable for Request<State> {
	fn as_value(&self) -> Value<'_> {
		Value::Structable(self)
	}

	fn visit(&self, visitor: &mut dyn Visit) {
		visitor.visit_named_fields(&NamedValues::new(
			REQUEST_FIELDS,
			&[
				Valuable::as_value(&format!("{:02X?}", self.body)),
				Valuable::as_value(&format!("{}", self.source_address)),
				Valuable::as_value(&self.stream_id),
				#[cfg(feature = "clients")]
				Valuable::as_value(&self.explicit_read_amount),
				#[cfg(feature = "servers")]
				Valuable::as_value(&if self.stream_access.is_some() {
					"<stream>"
				} else {
					"<none>"
				}),
			],
		));
	}
}

/// Just a generic response on an L4 Layer.
#[derive(Clone, Debug)]
pub struct Response {
	/// Get the body of the actual response to send. If empty, no response is sent.
	pub body: Option<Bytes>,
	/// If we should request any long-lived connections should be closed.
	///
	/// NOTE: not every type of Level 4 connection has a long lived connection,
	/// or stream. UDP is a prime example of this, this is not guaranteed.
	pub request_connection_close: bool,
}

impl Response {
	#[must_use]
	pub const fn new_empty() -> Self {
		Self {
			body: None,
			request_connection_close: false,
		}
	}
	#[must_use]
	pub const fn empty_close() -> Self {
		Self {
			body: None,
			request_connection_close: true,
		}
	}
	#[must_use]
	pub const fn new_with_body(body: Bytes) -> Self {
		Self {
			body: Some(body),
			request_connection_close: false,
		}
	}

	#[must_use]
	pub const fn body(&self) -> Option<&Bytes> {
		self.body.as_ref()
	}
	#[must_use]
	pub fn body_mut(&mut self) -> Option<&mut Bytes> {
		self.body.as_mut()
	}
	pub fn set_body(&mut self, bytes: Bytes) {
		self.body = Some(bytes);
	}
	#[must_use]
	pub fn take_body(self) -> Option<Bytes> {
		self.body
	}

	#[must_use]
	pub const fn request_connection_close(&self) -> bool {
		self.request_connection_close
	}
	pub fn should_close_connection(&mut self) {
		self.request_connection_close = true;
	}
	pub fn dont_close_connection(&mut self) {
		self.request_connection_close = false;
	}
}

impl Default for Response {
	fn default() -> Self {
		Self::new_empty()
	}
}

impl<ByteTy: Into<Bytes>> From<ByteTy> for Response {
	fn from(resp: ByteTy) -> Self {
		Self::new_with_body(resp.into())
	}
}

const RESPONSE_FIELDS: &[NamedField<'static>] = &[
	NamedField::new("body"),
	NamedField::new("request_connection_close"),
];

impl Structable for Response {
	fn definition(&self) -> StructDef<'_> {
		StructDef::new_static("Response", Fields::Named(RESPONSE_FIELDS))
	}
}

impl Valuable for Response {
	fn as_value(&self) -> Value<'_> {
		Value::Structable(self)
	}

	fn visit(&self, visitor: &mut dyn Visit) {
		visitor.visit_named_fields(&NamedValues::new(
			RESPONSE_FIELDS,
			&[
				Valuable::as_value(&if let Some(body_ref) = self.body.as_ref() {
					format!("{body_ref:02X?}")
				} else {
					"<empty>".to_owned()
				}),
				Valuable::as_value(&self.request_connection_close),
			],
		));
	}
}

/// Extract any value from a Request, allowing more people to keep using it.
///
/// Kept as our own trait so it can be async like axum.
pub trait FromRequestParts<State: Clone + Send + Sync + 'static>: Sized {
	fn from_request_parts(
		req: &mut Request<State>,
	) -> impl Future<Output = Result<Self, CatBridgeError>> + Send;
}

/// Extract any value from a Request, finalizing it.
///
/// Kept as our own trait so it can be async like axum.
pub trait FromRequest<State: Clone + Send + Sync + 'static>: Sized {
	fn from_request(
		req: Request<State>,
	) -> impl Future<Output = Result<Self, CatBridgeError>> + Send;
}
impl<State: Clone + Send + Sync + 'static> FromRequest<State> for Request<State> {
	async fn from_request(req: Request<State>) -> Result<Self, CatBridgeError> {
		Ok(req)
	}
}

/// A blanket trait to implement into a full response.
///
/// This was mainly implemented so functions that return things like
/// `Bytes`, can naturally get wrapped into a result without needing
/// to return a result themselves.
pub trait IntoResponse: Sized {
	/// Convert an arbitrary type to a Response.
	///
	/// # Errors
	///
	/// If for whatever reason the type can't be turned into a response.
	fn to_response(self) -> Result<Response, CatBridgeError>;
}

impl IntoResponse for () {
	fn to_response(self) -> Result<Response, CatBridgeError> {
		Ok(Response::new_empty())
	}
}
impl IntoResponse for Response {
	fn to_response(self) -> Result<Response, CatBridgeError> {
		Ok(self)
	}
}

macro_rules! impl_from_ok_response {
	($ty:ty) => {
		impl IntoResponse for $ty {
			fn to_response(self) -> Result<Response, CatBridgeError> {
				Ok(self.into())
			}
		}
	};
}
impl_from_ok_response!(Bytes);
impl_from_ok_response!(BytesMut);
impl_from_ok_response!(String);
impl_from_ok_response!(Vec<u8>);
impl_from_ok_response!(&'static [u8]);
impl_from_ok_response!(&'static str);

impl IntoResponse for CatBridgeError {
	fn to_response(self) -> Result<Response, CatBridgeError> {
		Err(self)
	}
}

impl<SomeTy: IntoResponse> IntoResponse for Option<SomeTy> {
	fn to_response(self) -> Result<Response, CatBridgeError> {
		if let Some(val) = self {
			val.to_response()
		} else {
			Ok(Response::new_empty())
		}
	}
}
impl<OkTy: IntoResponse> IntoResponse for Result<OkTy, CatBridgeError> {
	fn to_response(self) -> Result<Response, CatBridgeError> {
		self.and_then(IntoResponse::to_response)
	}
}

/// Nagle guard is what determines when a packet "begins", and "ends".
///
/// These are the various types of ways we determine where a packet begins,
/// and "ends".
#[derive(Clone, Debug, PartialEq, Eq, Hash, Valuable)]
pub enum NagleGuard {
	/// Search for a specific searchs of bytes to determine the "end" of a
	/// packet.
	EndSigilSearch(&'static [u8]),
	/// All packets are guaranteed to be the exact same length.
	StaticSize(usize),
	/// Packets will prefix their total length with a u16.
	///
	/// This includes the 'endianness' to parse the number as, and you can apply
	/// an extra length to add (incase the length doesn't say include the length
	/// of a header).
	U16LengthPrefixed(Endianness, Option<usize>),
	/// Packets will prefix their total length with a u32.
	///
	/// This includes the 'endianness' to parse the number as, and you can apply
	/// an extra length to add (incase the length doesn't say include the length
	/// of a header).
	U32LengthPrefixed(Endianness, Option<usize>),
}

impl NagleGuard {
	/// Split a buffer of bytes from potentially multiple packets.
	///
	/// ## Errors
	///
	/// If we are an "end sigil search" without a an actual sigil.
	pub fn split(&self, buff: &BytesMut) -> Result<Option<(usize, usize)>, CommonNetAPIError> {
		match *self {
			NagleGuard::EndSigilSearch(sigil) => {
				if sigil.is_empty() {
					return Err(CommonNetAPIError::NagleGuardEndSigilCannotBeEmpty);
				}
				if buff.is_empty() {
					return Ok(None);
				}

				for (idx, byte) in buff.iter().enumerate() {
					// Not enough room!
					if idx + sigil.len() > buff.len() {
						break;
					}
					if *byte == sigil[0] && sigil == &buff[idx..(idx + sigil.len())] {
						return Ok(Some((0, idx + sigil.len())));
					}
				}
			}
			NagleGuard::StaticSize(size) => {
				if buff.len() < size {
					return Ok(None);
				}

				return Ok(Some((0, size)));
			}
			NagleGuard::U16LengthPrefixed(endianness, extra_len) => {
				if buff.len() < 2 {
					return Ok(None);
				}
				let extra_len_frd = extra_len.unwrap_or_default();

				let total_size = match endianness {
					Endianness::Little => u16::from_le_bytes([buff[0], buff[1]]),
					Endianness::Big => u16::from_be_bytes([buff[0], buff[1]]),
				};
				if buff.len() >= usize::from(total_size) + extra_len_frd {
					return Ok(Some((0, usize::from(total_size) + extra_len_frd)));
				}
			}
			NagleGuard::U32LengthPrefixed(endianness, extra_len) => {
				if buff.len() < 4 {
					return Ok(None);
				}
				let extra_len_frd = extra_len.unwrap_or_default();

				let total_size = match endianness {
					Endianness::Little => u32::from_le_bytes([buff[0], buff[1], buff[2], buff[3]]),
					Endianness::Big => u32::from_be_bytes([buff[0], buff[1], buff[2], buff[3]]),
				};
				if buff.len() >= usize::try_from(total_size).unwrap_or(usize::MAX) + extra_len_frd {
					return Ok(Some((
						0,
						usize::try_from(total_size).unwrap_or(usize::MAX) + extra_len_frd,
					)));
				}
			}
		}

		Ok(None)
	}
}

impl From<usize> for NagleGuard {
	fn from(value: usize) -> Self {
		NagleGuard::StaticSize(value)
	}
}

impl From<&'static [u8]> for NagleGuard {
	fn from(value: &'static [u8]) -> Self {
		NagleGuard::EndSigilSearch(value)
	}
}

/// The endianness of a particular number coming in over the network.
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, Valuable)]
pub enum Endianness {
	/// The data is in little endian.
	Little,
	/// The data is in big endian.
	Big,
}

/// A function type that can be used to convert before passing onto nagle.
///
/// This is useful when we have an encrypted stream that needs to be decrypted,
/// before we end up applying any NAGLE, or other splitting logic to the
/// stream.
pub trait PreNagleFnTy: Fn(u64, &mut BytesMut) + Send + Sync + 'static {}
impl<FnTy: Fn(u64, &mut BytesMut) + Send + Sync + 'static> PreNagleFnTy for FnTy {}

/// A function type that can be used to convert data right before sending it
/// out.
///
/// This is useful when we have an encrypted stream that needs to be encrypted
/// before it goes out to the client.
pub trait PostNagleFnTy: Fn(u64, Bytes) -> Bytes + Send + Sync + 'static {}
impl<FnTy: Fn(u64, Bytes) -> Bytes + Send + Sync + 'static> PostNagleFnTy for FnTy {}