Skip to content

Commit

Permalink
remove pub on bytes data
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetbout committed Apr 12, 2024
1 parent df1b7b5 commit c8ba40a
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 101 deletions.
16 changes: 15 additions & 1 deletion src/bytes/src/bytes.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ const BYTES_PER_ELEMENT: usize = 16;
#[derive(Drop, Clone, PartialEq, Serde)]
pub struct Bytes {
size: usize,
pub data: Array<u128> // TODO should this be pub?
data: Array<u128>
}

pub impl BytesIndex of IndexView<Bytes, usize, @u128> {
fn index(self: @Bytes, index: usize) -> @u128 {
self.data[index]
}
}


pub trait BytesTrait {
/// Create a Bytes from an array of u128
fn new(size: usize, data: Array<u128>) -> Bytes;
Expand All @@ -48,6 +55,8 @@ pub trait BytesTrait {
fn locate(offset: usize) -> (usize, usize);
/// Get Bytes size
fn size(self: @Bytes) -> usize;
/// Get data
fn data(self: Bytes) -> Array<u128>;
/// update specific value (1 bytes) at specific offset
fn update_at(ref self: Bytes, offset: usize, value: u8);
/// Read value with size bytes from Bytes, and packed into u128
Expand Down Expand Up @@ -158,6 +167,11 @@ impl BytesImpl of BytesTrait {
*self.size
}


fn data(self: Bytes) -> Array<u128> {
self.data
}

/// update specific value (1 bytes) at specific offset
fn update_at(ref self: Bytes, offset: usize, value: u8) {
assert(offset < self.size(), 'update out of bound');
Expand Down
2 changes: 1 addition & 1 deletion src/bytes/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ pub mod bytes;
mod tests;
pub mod utils;

pub use bytes::{Bytes, BytesTrait};
pub use bytes::{Bytes, BytesTrait, BytesIndex};
Loading

0 comments on commit c8ba40a

Please sign in to comment.