mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-16 20:55:03 +01:00
codegen
This commit is contained in:
parent
e5fa49a05a
commit
d5fd9abdf7
10 changed files with 640 additions and 7 deletions
24
amqp_transport/src/classes/connection.rs
Normal file
24
amqp_transport/src/classes/connection.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
type Octet = u8;
|
||||
type PeerProperties = ();
|
||||
type LongStr = String;
|
||||
|
||||
pub enum Connection {
|
||||
Start {
|
||||
version_major: Option<u8>,
|
||||
version_minor: Option<u8>,
|
||||
server_properties: PeerProperties,
|
||||
mechanisms: LongStr,
|
||||
locales: LongStr,
|
||||
},
|
||||
StartOk,
|
||||
Secure,
|
||||
SecureOk,
|
||||
Tune,
|
||||
TuneOk,
|
||||
Open,
|
||||
OpenOk,
|
||||
Close,
|
||||
CloseOk,
|
||||
Blocked,
|
||||
Unblocked,
|
||||
}
|
||||
7
amqp_transport/src/classes/mod.rs
Normal file
7
amqp_transport/src/classes/mod.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
mod connection;
|
||||
|
||||
use crate::classes::connection::Connection;
|
||||
|
||||
pub enum Class {
|
||||
Connection(Connection),
|
||||
}
|
||||
|
|
@ -32,8 +32,8 @@ impl Connection {
|
|||
|
||||
async fn negotiate_version(&mut self) -> Result<(), TransError> {
|
||||
const HEADER_SIZE: usize = 8;
|
||||
const PROTOCOL_VERSION: &[u8] = &[0, 9, 1];
|
||||
const PROTOCOL_HEADER: &[u8] = b"AMQP\0\0\x09\x01";
|
||||
const SUPPORTED_PROTOCOL_VERSION: &[u8] = &[0, 9, 1];
|
||||
const OWN_PROTOCOL_HEADER: &[u8] = b"AMQP\0\0\x09\x01";
|
||||
|
||||
debug!("Negotiating version");
|
||||
|
||||
|
|
@ -49,15 +49,15 @@ impl Connection {
|
|||
let version = &read_header_buf[5..8];
|
||||
|
||||
self.stream
|
||||
.write_all(PROTOCOL_HEADER)
|
||||
.write_all(OWN_PROTOCOL_HEADER)
|
||||
.await
|
||||
.context("write protocol header")?;
|
||||
|
||||
if &read_header_buf[0..5] == b"AMQP\0" && version == PROTOCOL_VERSION {
|
||||
if &read_header_buf[0..5] == b"AMQP\0" && version == SUPPORTED_PROTOCOL_VERSION {
|
||||
debug!(?version, "Version negotiation successful");
|
||||
Ok(())
|
||||
} else {
|
||||
debug!(?version, expected_version = ?PROTOCOL_VERSION, "Version negotiation failed, unsupported version");
|
||||
debug!(?version, expected_version = ?SUPPORTED_PROTOCOL_VERSION, "Version negotiation failed, unsupported version");
|
||||
Err(ProtocolError::OtherCloseConnection.into())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
mod classes;
|
||||
mod connection;
|
||||
mod error;
|
||||
mod frame;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue