Skip to content

Commit

Permalink
rename constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Foivos committed Dec 12, 2024
1 parent cfbc9c8 commit 3106d50
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions move/abi/sources/abi.move
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use sui::bcs;
// ---------
// Constants
// ---------
const BYTES_IN_U256: u64 = 32;
const U256_BYTES: u64 = 32;

// -----
// Types
Expand Down Expand Up @@ -40,7 +40,7 @@ public fun new_reader(bytes: vector<u8>): AbiReader {

public fun new_writer(length: u64): AbiWriter {
AbiWriter {
bytes: vector::tabulate!(BYTES_IN_U256 * length, |_| 0),
bytes: vector::tabulate!(U256_BYTES * length, |_| 0),
pos: 0,
}
}
Expand All @@ -62,9 +62,9 @@ public fun read_u256(self: &mut AbiReader): u256 {
let mut var = 0u256;
let pos = self.pos;

BYTES_IN_U256.do!(|i| var = (var << 8) | (self.bytes[i + pos] as u256));
U256_BYTES.do!(|i| var = (var << 8) | (self.bytes[i + pos] as u256));

self.pos = pos + BYTES_IN_U256;
self.pos = pos + U256_BYTES;

var
}
Expand All @@ -74,7 +74,7 @@ public fun read_u8(self: &mut AbiReader): u8 {
}

public fun skip_slot(self: &mut AbiReader) {
self.pos = self.pos + BYTES_IN_U256;
self.pos = self.pos + U256_BYTES;
}

public fun read_bytes(self: &mut AbiReader): vector<u8> {
Expand All @@ -87,7 +87,7 @@ public fun read_bytes(self: &mut AbiReader): vector<u8> {
let var = self.decode_bytes();

// Move position to the next slot
self.pos = pos + BYTES_IN_U256;
self.pos = pos + U256_BYTES;

var
}
Expand All @@ -104,7 +104,7 @@ public fun read_vector_u256(self: &mut AbiReader): vector<u256> {

length.do!(|_| var.push_back(self.read_u256()));

self.pos = pos + BYTES_IN_U256;
self.pos = pos + U256_BYTES;

var
}
Expand All @@ -126,7 +126,7 @@ public fun read_vector_bytes(self: &mut AbiReader): vector<vector<u8>> {
length.do!(|_| var.push_back(self.read_bytes()));

// Move position to the next slot
self.pos = pos + BYTES_IN_U256;
self.pos = pos + U256_BYTES;
self.head = head;

var
Expand All @@ -146,13 +146,13 @@ public fun read_bytes_raw(self: &mut AbiReader): vector<u8> {
public fun write_u256(self: &mut AbiWriter, var: u256): &mut AbiWriter {
let pos = self.pos;

BYTES_IN_U256.do!(|i| {
U256_BYTES.do!(|i| {
let exp = ((31 - i) * 8 as u8);
let byte = (var >> exp & 255 as u8);
*&mut self.bytes[i + pos] = byte;
});

self.pos = pos + BYTES_IN_U256;
self.pos = pos + U256_BYTES;

self
}
Expand Down Expand Up @@ -398,7 +398,7 @@ fun test_raw_table() {
let mut length_bytes = vector[];

// Split the data into the lenth and the actual table contents
BYTES_IN_U256.do!(|_| length_bytes.push_back(table_bytes.remove(0)));
U256_BYTES.do!(|_| length_bytes.push_back(table_bytes.remove(0)));

let mut length_reader = new_reader(length_bytes);
let length = length_reader.read_u256();
Expand Down

0 comments on commit 3106d50

Please sign in to comment.