Spaces:
Configuration error
Configuration error
File size: 1,192 Bytes
5641073 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
/**
* @author jdiaz5513
*/
import initTrace from "debug";
import * as _ from "../util";
const trace = initTrace("capnp:object-size");
trace("load");
/**
* A simple object that describes the size of a struct.
*
* @export
* @class ObjectSize
*/
export class ObjectSize {
/** The number of bytes required for the data section. */
readonly dataByteLength: number;
/** The number of pointers in the object. */
readonly pointerLength: number;
constructor(dataByteLength: number, pointerCount: number) {
this.dataByteLength = dataByteLength;
this.pointerLength = pointerCount;
}
toString(): string {
return _.format(
"ObjectSize_dw:%d,pc:%d",
getDataWordLength(this),
this.pointerLength
);
}
}
export function getByteLength(o: ObjectSize): number {
return o.dataByteLength + o.pointerLength * 8;
}
export function getDataWordLength(o: ObjectSize): number {
return o.dataByteLength / 8;
}
export function getWordLength(o: ObjectSize): number {
return o.dataByteLength / 8 + o.pointerLength;
}
export function padToWord(o: ObjectSize): ObjectSize {
return new ObjectSize(_.padToWord(o.dataByteLength), o.pointerLength);
}
|