Skip to content
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
15 changes: 8 additions & 7 deletions src/common/util.mo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import Array "mo:stdlib/array.mo";
import Result "mo:stdlib/result.mo";
import Nat "mo:stdlib/nat.mo";

module Util {

Expand All @@ -17,7 +18,7 @@ module Util {
* Convert an unsigned 8-bit integer to an unsigned 32-bit integer.
*/
public func convWord8ToWord32(byte : Word8) : Word32 {
natToWord32(word8ToNat(byte))
Nat.toWord32(Nat.fromWord8(byte))
};

/**
Expand All @@ -27,7 +28,7 @@ module Util {
var n = 0;
var i = 0;
Array.foldr<Word8, ()>(func (byte, _) {
n += word8ToNat(byte) * 256 ** i;
n += Nat.fromWord8(byte) * 256 ** i;
i += 1
}, (), bytes);
n
Expand Down Expand Up @@ -57,7 +58,7 @@ module Util {
n : Nat,
next : () -> ?Word8
) : Result<[Word8], Text> {
var bytes = Array_init<Word8>(n, 0);
var bytes = Array.init<Word8>(n, 0);
var i = 0;
while (i < n) {
switch (decodeWord8(next)) {
Expand Down Expand Up @@ -92,7 +93,7 @@ module Util {
f : [Word8] -> Result<T, Text>
) : Result<T, Text> {
decodeWord8Then<T>(next, func (n) {
decodeWord8ArrayThen<T>(word8ToNat(n), next, f)
decodeWord8ArrayThen<T>(Nat.fromWord8(n), next, f)
})
};

Expand All @@ -104,7 +105,7 @@ module Util {
f : [Word8] -> Result<T, Text>
) : Result<T, Text> {
decodeWord16Then<T>(next, func (n) {
decodeWord8ArrayThen<T>(word16ToNat(n), next, f)
decodeWord8ArrayThen<T>(Nat.fromWord16(n), next, f)
})
};

Expand All @@ -115,7 +116,7 @@ module Util {
Result.mapOk<[Word8], Word16, Text>(
decodeWord8Array(2, next),
func (bytes) {
natToWord16(convWord8ArrayToNat(bytes))
Nat.toWord16(convWord8ArrayToNat(bytes))
}
)
};
Expand All @@ -137,7 +138,7 @@ module Util {
Result.mapOk<[Word8], Word64, Text>(
decodeWord8Array(8, next),
func (bytes) {
natToWord64(convWord8ArrayToNat(bytes))
Nat.toWord64(convWord8ArrayToNat(bytes))
}
)
};
Expand Down