This commit is contained in:
2025-08-06 16:22:19 +03:00
parent 16789a942e
commit 40dc6a2637
20 changed files with 250 additions and 183 deletions

View File

@ -1,5 +1,5 @@
import { memcpy } from "./mem"
import { Type } from "./Type"
import { memcpy } from './mem'
import { Type } from './Type'
export function ConstString(size) {
const obj = { _size: size }
@ -7,7 +7,7 @@ export function ConstString(size) {
obj.new(ConstString, arguments)
return obj
}
ConstString.prototype.serialize = function(dv, src) {
ConstString.prototype.serialize = function (dv, src) {
const encoder = new TextEncoder('utf-8')
const encoded = new DataView(encoder.encode(src).buffer, 0, this._size)
@ -21,15 +21,15 @@ ConstString.prototype.serialize = function(dv, src) {
memcpy(dv, encoded)
return
}
ConstString.prototype.parse = function(dv) {
ConstString.prototype.parse = function (dv) {
const frame = new DataView(dv.buffer, dv.byteOffset, this._size)
const decoder = new TextDecoder('utf-8')
return decoder.decode(frame)
}
ConstString.prototype.isHeadless = function() {
ConstString.prototype.isHeadless = function () {
return false
}
ConstString.prototype.sizeof = function() {
ConstString.prototype.sizeof = function () {
return this._size
}
Object.setPrototypeOf(ConstString.prototype, Type.prototype)