mirror of
https://github.com/Noratrieb/haesli.git
synced 2026-01-14 19:55:03 +01:00
fixed class and method index
This commit is contained in:
parent
217a419ef1
commit
2903ba108e
8 changed files with 1208 additions and 1226 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
||||||
/target
|
/target
|
||||||
.idea
|
.idea
|
||||||
|
amqp0-9-1.xml
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
# amqp
|
# amqp
|
||||||
|
|
||||||
https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf
|
[amqp0-9-1 spec pdf](https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf)
|
||||||
|
|
||||||
https://www.rabbitmq.com/resources/specs/amqp-xml-doc0-9-1.pdf
|
[amqp 0-9-1 spec generated_pdf](https://www.rabbitmq.com/resources/specs/amqp-xml-doc0-9-1.pdf)
|
||||||
|
|
||||||
|
[amqp0-9-1 spec xml](https://www.rabbitmq.com/resources/specs/amqp0-9-1.xml)
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ struct Field {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let content = fs::read_to_string("./amqp-0-9-1.xml").unwrap();
|
let content = fs::read_to_string("./amqp-0-9-1-bsd.xml").unwrap();
|
||||||
|
|
||||||
let amqp = Amqp::from_str(&content).unwrap();
|
let amqp = Amqp::from_str(&content).unwrap();
|
||||||
codegen(&amqp);
|
codegen(&amqp);
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ pub fn write_method<W: Write>(class: Class, mut writer: W) -> Result<(), TransEr
|
||||||
println!(" {field_name},");
|
println!(" {field_name},");
|
||||||
}
|
}
|
||||||
println!(" }}) => {{");
|
println!(" }}) => {{");
|
||||||
println!(" writer.write_all(&[{class_index}, {method_index}])?;");
|
let [ci0, ci1] = class_index.to_be_bytes();
|
||||||
|
let [mi0, mi1] = method_index.to_be_bytes();
|
||||||
|
println!(" writer.write_all(&[{ci0}, {ci1}, {mi0}, {mi1}])?;");
|
||||||
let mut iter = method.fields.iter().peekable();
|
let mut iter = method.fields.iter().peekable();
|
||||||
|
|
||||||
while let Some(field) = iter.next() {
|
while let Some(field) = iter.next() {
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,10 +1,13 @@
|
||||||
|
use crate::classes::FieldValue;
|
||||||
use crate::error::{ProtocolError, Result};
|
use crate::error::{ProtocolError, Result};
|
||||||
use crate::frame::{Frame, FrameType};
|
use crate::frame::{Frame, FrameType};
|
||||||
use crate::{classes, frame};
|
use crate::{classes, frame};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
|
use std::collections::HashMap;
|
||||||
|
use std::net::SocketAddr;
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
use tokio::net::TcpStream;
|
use tokio::net::TcpStream;
|
||||||
use tracing::{debug, error, warn};
|
use tracing::{debug, error};
|
||||||
|
|
||||||
const MIN_MAX_FRAME_SIZE: usize = 4096;
|
const MIN_MAX_FRAME_SIZE: usize = 4096;
|
||||||
|
|
||||||
|
|
@ -46,11 +49,17 @@ impl Connection {
|
||||||
let start_method = classes::Class::Connection(classes::Connection::Start {
|
let start_method = classes::Class::Connection(classes::Connection::Start {
|
||||||
version_major: 0,
|
version_major: 0,
|
||||||
version_minor: 9,
|
version_minor: 9,
|
||||||
server_properties: Default::default(),
|
server_properties: server_properties(
|
||||||
mechanisms: vec![],
|
self.stream
|
||||||
locales: vec![],
|
.local_addr()
|
||||||
|
.context("failed to get local_addr")?,
|
||||||
|
),
|
||||||
|
mechanisms: "none".to_string().into(),
|
||||||
|
locales: "en_US".to_string().into(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
debug!(?start_method, "Sending start method");
|
||||||
|
|
||||||
let mut payload = Vec::with_capacity(64);
|
let mut payload = Vec::with_capacity(64);
|
||||||
classes::write::write_method(start_method, &mut payload)?;
|
classes::write::write_method(start_method, &mut payload)?;
|
||||||
frame::write_frame(
|
frame::write_frame(
|
||||||
|
|
@ -98,3 +107,27 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn server_properties(host: SocketAddr) -> classes::Table {
|
||||||
|
fn ss(str: &str) -> FieldValue {
|
||||||
|
FieldValue::ShortString(str.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
let host_str = host.ip().to_string();
|
||||||
|
let host_value = if host_str.len() < 256 {
|
||||||
|
FieldValue::ShortString(host_str)
|
||||||
|
} else {
|
||||||
|
FieldValue::LongString(host_str.into())
|
||||||
|
};
|
||||||
|
|
||||||
|
//HashMap::from([
|
||||||
|
// ("host".to_string(), host_value),
|
||||||
|
// ("product".to_string(), ss("no name yet")),
|
||||||
|
// ("version".to_string(), ss("0.1.0")),
|
||||||
|
// ("platform".to_string(), ss("microsoft linux")),
|
||||||
|
// ("copyright".to_string(), ss("MIT")),
|
||||||
|
// ("information".to_string(), ss("hello reader")),
|
||||||
|
// ("uwu".to_string(), ss("owo")),
|
||||||
|
//])
|
||||||
|
HashMap::new()
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
use crate::error::{ConException, ProtocolError, Result, TransError};
|
use crate::error::{ConException, ProtocolError, Result, TransError};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
const REQUIRED_FRAME_END: u8 = 0xCE;
|
const REQUIRED_FRAME_END: u8 = 0xCE;
|
||||||
|
|
||||||
|
|
@ -33,6 +34,8 @@ pub async fn write_frame<W>(mut w: W, frame: &Frame) -> Result<()>
|
||||||
where
|
where
|
||||||
W: AsyncWriteExt + Unpin,
|
W: AsyncWriteExt + Unpin,
|
||||||
{
|
{
|
||||||
|
debug!(?frame, "sending frame");
|
||||||
|
|
||||||
w.write_u8(frame.kind as u8).await?;
|
w.write_u8(frame.kind as u8).await?;
|
||||||
w.write_u16(frame.channel).await?;
|
w.write_u16(frame.channel).await?;
|
||||||
w.write_u32(u32::try_from(frame.payload.len()).context("frame size too big")?)
|
w.write_u32(u32::try_from(frame.payload.len()).context("frame size too big")?)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue