Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's wrong with my struct/code? #722

Closed
IoIxD opened this issue Aug 16, 2024 · 1 comment
Closed

What's wrong with my struct/code? #722

IoIxD opened this issue Aug 16, 2024 · 1 comment

Comments

@IoIxD
Copy link

IoIxD commented Aug 16, 2024

struct:

#[repr(C)]
#[derive(Clone, Encode, Decode)]
pub struct BoxDimensions {
    pub x: f32,
    pub y: f32,
    pub width: f32,
    pub height: f32,
}

#[repr(C)]
#[derive(Decode, Encode)]
pub struct FetchedColliders {
    packet_type: PacketType,
    pub vec: Vec<BoxDimensions>,
}

deserialization function:

pub fn deserialize<'a, T>(mut bytes: BufReader<&TcpStream>) -> Result<T, Box<dyn std::error::Error>>
where
    T: Decode,
{
    Ok(bincode::decode_from_reader(&mut bytes, config::standard())?)
}

function that calls it:

 pub fn colliders(&mut self) -> Result<Vec<BoxDimensions>, Box<dyn std::error::Error>> {
        let tcp = Self::tcp()?;

        let mut reader = BufReader::new(&tcp);
        let mut writer = BufWriter::new(&tcp);

        writer.write(&[PacketType::FetchCollidersPacket as u8])?;
        writer.write_all(&serialize(FetchColliders::new())?)?;

        writer.flush();

        let vec: Vec<BoxDimensions> = deserialize(reader)?;
        Ok(vec.clone())
    }

On both 1.0, and 2.0, I get an "unexpected eof" error, even though I confirmed that after flushing the writer, I can in fact read the struct with reader.read_to_end; I even tried just saving the result of that function to a vec and then passing it to bincode::decode_from_slice , but I get the same error.

@IoIxD
Copy link
Author

IoIxD commented Aug 16, 2024

Realized this is a duplicate of #695

@IoIxD IoIxD closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant