Skip to content

Commit

Permalink
fix[rust]: write no protocol id error
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysunxiao committed Jul 21, 2024
1 parent 2a3ba99 commit 54d1c45
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 4 additions & 4 deletions protocol/src/main/resources/rust/byte_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#![allow(non_camel_case_types)]
use std::any::Any;
use crate::${protocol_root_path}::i_byte_buffer::IByteBuffer;
use crate::${protocol_root_path}::protocol_manager::write;
use crate::${protocol_root_path}::protocol_manager::readByProtocolId;
use crate::${protocol_root_path}::protocol_manager::writeNoProtocolId;
use crate::${protocol_root_path}::protocol_manager::readNoProtocolId;

#[allow(non_snake_case)]
pub struct ByteBuffer {
Expand Down Expand Up @@ -443,10 +443,10 @@ impl IByteBuffer for ByteBuffer {
}

fn writePacket(&mut self, packet: &dyn Any, protocolId: i16) {
write(self, packet, protocolId);
writeNoProtocolId(self, packet, protocolId);
}

fn readPacket(&mut self, protocolId: i16) -> Box<dyn Any> {
return readByProtocolId(self, protocolId);
return readNoProtocolId(self, protocolId);
}
}
10 changes: 8 additions & 2 deletions protocol/src/main/resources/rust/protocol_manager_template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ use std::any::Any;
use crate::${protocol_root_path}::i_byte_buffer::IByteBuffer;
${protocol_imports}


pub fn write(buffer: &mut dyn IByteBuffer, packet: &dyn Any, protocolId: i16) {
buffer.writeShort(protocolId);
writeNoProtocolId(buffer, packet, protocolId);
}

pub fn writeNoProtocolId(buffer: &mut dyn IByteBuffer, packet: &dyn Any, protocolId: i16) {
match protocolId {
${protocol_write_serialization}
_ => println!("protocolId:[{}] not found", protocolId)
Expand All @@ -15,10 +21,10 @@ pub fn write(buffer: &mut dyn IByteBuffer, packet: &dyn Any, protocolId: i16) {

pub fn read(buffer: &mut dyn IByteBuffer) -> Box<dyn Any> {
let protocolId = buffer.readShort();
return readByProtocolId(buffer, protocolId);
return readNoProtocolId(buffer, protocolId);
}

pub fn readByProtocolId(buffer: &mut dyn IByteBuffer, protocolId: i16) -> Box<dyn Any> {
pub fn readNoProtocolId(buffer: &mut dyn IByteBuffer, protocolId: i16) -> Box<dyn Any> {
let packet = match protocolId {
${protocol_read_deserialization}
_ => Box::new(String::from("protocolId not found"))
Expand Down

0 comments on commit 54d1c45

Please sign in to comment.