GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — ... · Defman/feather-protocol@aa27287

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • codegen/src
    • generation.rs
  • protocols
    • 1.15.2.ron
  • spec/src
    • main.rs
    • primitives.rs
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎codegen/src/generation.rs‎

Copy file name to clipboardExpand all lines: codegen/src/generation.rs
+29-37Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,9 @@ pub struct ProtocolGenerator;
1515
impl ProtocolGenerator {
1616
pub fn generate(protocol: Protocol) -> TokenStream {
1717
let mut packets = protocol.packets;
18-
let server_bound_packets = packets.split_off(&PacketIdentifier {
19-
direction: PacketDirection::ServerBound,
20-
stage: PacketStage::Handshaking,
21-
id: 0.into(),
22-
});
23-
24-
let client_bound_packets = packets.split_off(&PacketIdentifier {
25-
direction: PacketDirection::ClientBound,
26-
stage: PacketStage::Handshaking,
27-
id: 0.into(),
28-
});
18+
let server_bound_packets = packets.split_off(&PacketIdentifier(PacketDirection::ServerBound, PacketStage::Handshaking, 0.into()));
19+
20+
let client_bound_packets = packets.split_off(&PacketIdentifier(PacketDirection::ClientBound, PacketStage::Handshaking, 0.into()));
2921

3022
let (client, _, _) = DirectionGenerator::generate(
3123
PacketDirection::ServerBound,
@@ -54,29 +46,29 @@ impl DirectionGenerator {
5446
) -> (TokenStream, (Ident, Ident, Ident, Ident), Ident) {
5547
let direction_ident = Self::ident(direction);
5648

57-
let play_packets = packets.split_off(&PacketIdentifier {
58-
direction: direction,
59-
stage: PacketStage::Play,
60-
id: 0.into(),
61-
});
62-
63-
let login_packets = packets.split_off(&PacketIdentifier {
64-
direction: direction,
65-
stage: PacketStage::Login,
66-
id: 0.into(),
67-
});
68-
69-
let status_packets = packets.split_off(&PacketIdentifier {
70-
direction: direction,
71-
stage: PacketStage::Status,
72-
id: 0.into(),
73-
});
74-
75-
let handshaking_packets = packets.split_off(&PacketIdentifier {
76-
direction: direction,
77-
stage: PacketStage::Handshaking,
78-
id: 0.into(),
79-
});
49+
let play_packets = packets.split_off(&PacketIdentifier(
50+
direction,
51+
PacketStage::Play,
52+
0.into(),
53+
));
54+
55+
let login_packets = packets.split_off(&PacketIdentifier(
56+
direction,
57+
PacketStage::Login,
58+
0.into(),
59+
));
60+
61+
let status_packets = packets.split_off(&PacketIdentifier(
62+
direction,
63+
PacketStage::Status,
64+
0.into(),
65+
));
66+
67+
let handshaking_packets = packets.split_off(&PacketIdentifier(
68+
direction,
69+
PacketStage::Handshaking,
70+
0.into(),
71+
));
8072

8173
let (handshaking, handshaking_ident) = StageGenerator::generate(
8274
direction,
@@ -186,10 +178,10 @@ impl PacketGenerator {
186178
let ident = Ident::new(&format!("{}_packet", *packet.name), Span::call_site());
187179
let (custom_type, custom_type_ident) = CustomTypeGenerator::generate("packet", &packet.custom_type);
188180

189-
let id_lit = LitInt::new(&identifier.id.to_string(), Span::call_site());
181+
let id_lit = LitInt::new(&identifier.id().to_string(), Span::call_site());
190182
let name_lit = LitStr::new(&*packet.name, Span::call_site());
191183

192-
let direction = match identifier.direction {
184+
let direction = match identifier.direction() {
193185
PacketDirection::ClientBound => {
194186
quote! { feather_protocol::PacketDirection::ClientBound }
195187
}
@@ -198,7 +190,7 @@ impl PacketGenerator {
198190
}
199191
};
200192

201-
let stage = match identifier.stage {
193+
let stage = match identifier.stage() {
202194
PacketStage::Handshaking => quote! { feather_protocol::PacketStage::Handshaking },
203195
PacketStage::Status => quote! { feather_protocol::PacketStage::Status },
204196
PacketStage::Login => quote! { feather_protocol::PacketStage::Login },
Collapse file

‎protocols/1.15.2.ron‎

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
(
2+
version: 578,
3+
packets: {
4+
(ServerBound, Handshaking, 0): (
5+
name: "handshake",
6+
custom_type: Struct({
7+
"protocol_version": VarInt,
8+
"server_address": String(255),
9+
"server_port": U16,
10+
"next_state": CustomType("state", Enum(
11+
variant: Prefixed(VarInt),
12+
variants: {
13+
(1, "status"): Unit,
14+
(2, "login"): Unit,
15+
}
16+
))
17+
})
18+
)
19+
},
20+
shared_types: {}
21+
)
Collapse file

‎spec/src/main.rs‎

Copy file name to clipboard
+24-2Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1-
fn main() {
2-
// Prettyfie protocol files
1+
use std::fs;
2+
use std::env;
3+
use std::io::Read;
4+
use anyhow::{Result, anyhow};
5+
use feather_protocol_spec::Protocol;
6+
7+
fn main() -> Result<()> {
8+
verify()?;
9+
Ok(())
10+
}
11+
12+
fn verify() -> Result<()> {
13+
let path = env::args()
14+
.skip(1)
15+
.next()
16+
.ok_or(anyhow!("Specify a file path to verify."))?;
17+
let file = fs::File::open(&path)?;
18+
19+
let _: Protocol = ron::de::from_reader(file)
20+
.map_err(|e| anyhow!("{}", e))?;
21+
22+
println!("Its all good");
23+
24+
Ok(())
325
}
Collapse file

‎spec/src/primitives.rs‎

Copy file name to clipboardExpand all lines: spec/src/primitives.rs
+17-7Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ macro_rules! wrap {
3232
};
3333
}
3434

35-
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
35+
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
3636
#[serde(transparent)]
3737
pub struct PacketId(u64);
3838

@@ -44,7 +44,7 @@ pub struct PacketName(String);
4444
#[serde(transparent)]
4545
pub struct MinecraftVersion(String);
4646

47-
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
47+
#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
4848
#[serde(transparent)]
4949
pub struct ProtocolVersion(u64);
5050

@@ -71,8 +71,18 @@ wrap!(FieldName, String);
7171

7272

7373
#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Serialize, Deserialize)]
74-
pub struct PacketIdentifier {
75-
pub direction: PacketDirection,
76-
pub stage: PacketStage,
77-
pub id: PacketId,
78-
}
74+
pub struct PacketIdentifier(pub PacketDirection, pub PacketStage, pub PacketId);
75+
76+
impl PacketIdentifier {
77+
pub fn direction(&self) -> PacketDirection {
78+
self.0
79+
}
80+
81+
pub fn stage(&self) -> PacketStage {
82+
self.1
83+
}
84+
85+
pub fn id(&self) -> PacketId {
86+
self.2
87+
}
88+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.