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

Lil' fixes #67

Merged
merged 1 commit into from
Jan 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 8 additions & 54 deletions lcmux/src/frames.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,30 +300,9 @@ impl Encodable for MessageFieldU64 {
where
C: BulkConsumer<Item = u8>,
{
if self.0 <= 251 {
// Encode channel as 8 bit integer
ufotofu_codec_endian::U8BE(self.0 as u8)
.encode(consumer)
.await?;
} else if self.0 <= 255 {
consumer.consume(252).await?;
ufotofu_codec_endian::U8BE(self.0 as u8)
.encode(consumer)
.await?;
} else if self.0 <= 2_u64.pow(16) {
consumer.consume(253).await?;
ufotofu_codec_endian::U16BE(self.0 as u16)
.encode(consumer)
.await?;
} else if self.0 <= 2_u64.pow(32) {
consumer.consume(254).await?;
ufotofu_codec_endian::U32BE(self.0 as u32)
.encode(consumer)
.await?;
} else {
consumer.consume(255).await?;
ufotofu_codec_endian::U64BE(self.0).encode(consumer).await?;
}
CompactU64(self.0)
.relative_encode(consumer, &compact_u64::EncodingWidth::eight())
.await?;

Ok(())
}
Expand All @@ -339,37 +318,13 @@ impl Decodable for MessageFieldU64 {
P: ufotofu::BulkProducer<Item = u8>,
Self: Sized,
{
let first_byte = producer.produce_item().await?;
let tag = Tag::min_tag(0, TagWidth::eight());

let value = match first_byte {
252 => {
ufotofu_codec_endian::U8BE::decode(producer)
.await
.map_err(DecodeError::map_other_from)?
.0 as u64
}
253 => {
ufotofu_codec_endian::U16BE::decode(producer)
.await
.map_err(DecodeError::map_other_from)?
.0 as u64
}
254 => {
ufotofu_codec_endian::U32BE::decode(producer)
.await
.map_err(DecodeError::map_other_from)?
.0 as u64
}
255 => {
ufotofu_codec_endian::U64BE::decode(producer)
.await
.map_err(DecodeError::map_other_from)?
.0 as u64
}
value => value as u64,
};
let value = CompactU64::relative_decode(producer, &tag)
.await
.map_err(DecodeError::map_other_from)?;

Ok(MessageFieldU64(value))
Ok(MessageFieldU64(value.0))
}
}

Expand Down Expand Up @@ -447,7 +402,6 @@ impl Encodable for HeaderWithEmbeddedChannelAndMaybeLength {
// Encode the length in only as many bytes as we need...
let length_bytes = length.to_be_bytes();

// TODO: move this into a *const* function, just because it can be.
let bytes_to_consume = min_bytes_needed(*length) as usize;

let slice = &length_bytes[8 - bytes_to_consume..];
Expand Down
Loading