feat(DataView, ConstDataView)
This commit is contained in:
31
src/ConstDataView.js
Normal file
31
src/ConstDataView.js
Normal file
@ -0,0 +1,31 @@
|
||||
import { memcpy, Type } from "."
|
||||
|
||||
export function ConstDataView(size) {
|
||||
const obj = { _size: size }
|
||||
Object.setPrototypeOf(obj, ConstDataView.prototype)
|
||||
obj.new(ConstDataView, arguments)
|
||||
return obj
|
||||
}
|
||||
ConstDataView.prototype.serialize = function(dv, src) {
|
||||
if (dv.byteLength < this._size) {
|
||||
throw new Error('too small buffer')
|
||||
}
|
||||
memcpy(dv, src)
|
||||
return
|
||||
}
|
||||
ConstDataView.prototype.parse = function(dv) {
|
||||
const res_buffer = new ArrayBuffer(this._size)
|
||||
const res_dv = new DataView(res_buffer)
|
||||
|
||||
memcpy(res_dv, dv)
|
||||
|
||||
return res_dv
|
||||
}
|
||||
ConstDataView.prototype.isHeadless = function() {
|
||||
return false
|
||||
}
|
||||
ConstDataView.prototype.sizeof = function() {
|
||||
return this._size
|
||||
}
|
||||
Object.setPrototypeOf(ConstDataView.prototype, Type.prototype)
|
||||
Object.freeze(ConstDataView.prototype)
|
||||
Reference in New Issue
Block a user