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

Fix inappropriate naming of u8Array<>bytes #98

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/collections/unordered-map.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as near from '../api'
import {u8ArrayToString, stringToU8Array} from '../utils'
import {u8ArrayToBytes, bytesToU8Array} from '../utils'
import { Vector, VectorIterator } from './vector'

const ERR_INCONSISTENT_STATE = "The collection is an inconsistent state. Did previous smart contract execution terminate unexpectedly?"
Expand Down Expand Up @@ -35,11 +35,11 @@ export class UnorderedMap {
serializeIndex(index) {
let data = new Uint32Array([index])
let array = new Uint8Array(data.buffer)
return u8ArrayToString(array)
return u8ArrayToBytes(array)
}

deserializeIndex(rawIndex) {
let array = stringToU8Array(rawIndex)
let array = bytesToU8Array(rawIndex)
let data = new Uint32Array(array.buffer)
return data[0]
}
Expand Down
6 changes: 3 additions & 3 deletions src/collections/unordered-set.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as near from '../api'
import {u8ArrayToString, stringToU8Array} from '../utils'
import {u8ArrayToBytes, bytesToU8Array} from '../utils'
import { Vector } from './vector'

const ERR_INCONSISTENT_STATE = "The collection is an inconsistent state. Did previous smart contract execution terminate unexpectedly?"
Expand All @@ -23,11 +23,11 @@ export class UnorderedSet {
serializeIndex(index) {
let data = new Uint32Array([index])
let array = new Uint8Array(data.buffer)
return u8ArrayToString(array)
return u8ArrayToBytes(array)
}

deserializeIndex(rawIndex) {
let array = stringToU8Array(rawIndex)
let array = bytesToU8Array(rawIndex)
let data = new Uint32Array(array.buffer)
return data[0]
}
Expand Down
4 changes: 2 additions & 2 deletions src/collections/vector.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as near from '../api'
import {u8ArrayToString} from '../utils'
import {u8ArrayToBytes} from '../utils'

const ERR_INDEX_OUT_OF_BOUNDS = "Index out of bounds"
const ERR_INCONSISTENT_STATE = "The collection is an inconsistent state. Did previous smart contract execution terminate unexpectedly?"
Expand All @@ -23,7 +23,7 @@ export class Vector {
indexToKey(index) {
let data = new Uint32Array([index])
let array = new Uint8Array(data.buffer)
let key = u8ArrayToString(array)
let key = u8ArrayToBytes(array)
return this.prefix + key
}

Expand Down
10 changes: 5 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
export function u8ArrayToString(array) {
export function u8ArrayToBytes(array) {
let ret = ''
for (let e of array) {
ret += String.fromCharCode(e)
}
return ret
}

export function stringToU8Array(string) {
let ret = new Uint8Array(string.length)
for (let i in string) {
ret[i] = string.charCodeAt(i)
export function bytesToU8Array(bytes) {
let ret = new Uint8Array(bytes.length)
for (let i in bytes) {
ret[i] = bytes.charCodeAt(i)
}
return ret
}