author jdiaz5513
  import initTrace from "debug" ; import { ListElementSize } from "../list-element-size" ; import { List } from "./list" ; import { Pointer , validate , getContent } from "./pointer" ; import { PointerType } from "./pointer-type" ; const trace = initTrace ( "capnp:data" ) ; trace ( "load" ) ; export class extends List < number > export class Data extends List < number > { static fromPointer ( pointer ) { validate ( PointerType . LIST , pointer , ListElementSize . BYTE ) ; return this . _fromPointerUnchecked ( pointer ) ; } protected static _fromPointerUnchecked ( pointer ) { return new this ( pointer . segment , pointer . byteOffset , pointer . _capnp . depthLimit ) ; } param { ( ArrayBuffer | ArrayBufferView ) } src returns { void } copyBuffer ( src ) { const c = getContent ( this ) ; const dstLength = this . getLength ( ) ; const srcLength = src . byteLength ; const i = src instanceof ArrayBuffer ? new Uint8Array ( src ) : new Uint8Array ( src . buffer , src . byteOffset , Math . min ( dstLength , srcLength ) ) ; const o = new Uint8Array ( c . segment . buffer , c . byteOffset , this . getLength ( ) ) ; o . set ( i ) ; if ( dstLength > srcLength ) { trace ( "Zeroing out remaining %d bytes after copy into %s." , dstLength - srcLength , this ) ; o . fill ( 0 , srcLength , dstLength ) ; } else if ( dstLength < srcLength ) { trace ( "Truncated %d bytes from source buffer while copying to %s." , srcLength - dstLength , this ) ; } } param { number } byteOffset returns { number } get ( byteOffset ) { const c = getContent ( this ) ; return c . segment . getUint8 ( c . byteOffset + byteOffset ) ; } param { number } byteOffset param { number } value returns { void } set ( byteOffset , value ) { const c = getContent ( this ) ; c . segment . setUint8 ( c . byteOffset + byteOffset , value ) ; } returns { ArrayBuffer } toArrayBuffer ( ) { const c = getContent ( this ) ; return c . segment . buffer . slice ( c . byteOffset , c . byteOffset + this . getLength ( ) ) ; } returns { DataView } toDataView ( ) { const c = getContent ( this ) ; return new DataView ( c . segment . buffer , c . byteOffset , this . getLength ( ) ) ; } toString ( ) { return `Data_${ super . toString ( ) }` ; } returns { DataView } toUint8Array ( ) { const c = getContent ( this ) ; return new Uint8Array ( c . segment . buffer , c . byteOffset , this . getLength ( ) ) ; } }