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

feat: Add bytes to Bytecode #1396

Merged
merged 3 commits into from
May 12, 2024
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
20 changes: 20 additions & 0 deletions crates/primitives/src/bytecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,26 @@ impl Bytecode {
!matches!(self, Self::LegacyRaw(_))
}

/// Returns bytes
#[inline]
pub fn bytes(&self) -> Bytes {
match self {
Self::LegacyRaw(bytes) => bytes.clone(),
Self::LegacyAnalyzed(analyzed) => analyzed.bytecode().clone(),
Self::Eof(eof) => eof.raw().clone(),
}
}

/// Returns bytes slice
#[inline]
pub fn bytes_slice(&self) -> &[u8] {
match self {
Self::LegacyRaw(bytes) => bytes,
Self::LegacyAnalyzed(analyzed) => analyzed.bytecode(),
Self::Eof(eof) => eof.raw(),
}
}

/// Returns a reference to the original bytecode.
#[inline]
pub fn original_bytes(&self) -> Bytes {
Expand Down
Loading