64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
/**
|
|
* @typedef {Object} Login The login object
|
|
* @property {string} Email Email of the user
|
|
* @property {string} Password Password of the user
|
|
*/
|
|
class Login {
|
|
/**
|
|
* Email of the user
|
|
* @return {string} gets the value of Email
|
|
*/
|
|
get Email() {
|
|
return this._decoder.decode(new Uint8Array(this._ptr.slice(0, 256)));
|
|
}
|
|
/**
|
|
* Email of the user
|
|
* @param {string} v sets the value of Email
|
|
*/
|
|
set Email(v) {
|
|
if (v.length > 256) {
|
|
throw new Error("input is larger than buffer size of 256");
|
|
}
|
|
const tmp = new Uint8Array(new ArrayBuffer(256));
|
|
tmp.set(this._encoder.encode(v))
|
|
this._ptr.set(tmp.buffer, 0);
|
|
}
|
|
/**
|
|
* Password of the user
|
|
* @return {string} gets the value of Password
|
|
*/
|
|
get Password() {
|
|
return this._decoder.decode(new Uint8Array(this._ptr.slice(256, 320)));
|
|
}
|
|
/**
|
|
* Password of the user
|
|
* @param {string} v sets the value of Password
|
|
*/
|
|
set Password(v) {
|
|
if (v.length > 64) {
|
|
throw new Error("input is larger than buffer size of 64");
|
|
}
|
|
const tmp = new Uint8Array(new ArrayBuffer(64));
|
|
tmp.set(this._encoder.encode(v))
|
|
this._ptr.set(tmp.buffer, 256);
|
|
}
|
|
/**
|
|
* Constructs a new Login
|
|
*
|
|
* @param {{Email: string, Password: string, }} init The arguments to construct the object.
|
|
* @param {Uint8Array} ptr The pointer to the C struct.
|
|
*/
|
|
constructor(init = {}, ptr = undefined) {
|
|
this._size = 320;
|
|
this._ptr = ptr || new Uint8Array(this._size);
|
|
this._data = new DataView(this._ptr.buffer);
|
|
|
|
this._encoder = new TextEncoder();
|
|
this._decoder = new TextDecoder();
|
|
for (const key of Object.keys(init)) {
|
|
this[key] = init[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
export default Login |