Add "ref-struct" module

This commit is contained in:
Paul Loyd
2013-09-10 21:43:05 +04:00
parent 660cb0bf91
commit 8bbceef0c2
2 changed files with 81 additions and 3 deletions
+58 -3
View File
@@ -6,9 +6,7 @@
/// <reference path="../node/node.d.ts" />
declare module "ffi" {
// import StructType = require('ref-struct');
export interface StructType {}
import StructType = require('ref-struct');
export interface Type {
/** The size in bytes required to hold this datatype. */
@@ -435,3 +433,60 @@ interface NodeBuffer {
*/
inspect(): string;
}
declare module "ref-struct" {
import ffi = require('ffi');
/**
* This is the `constructor` of the Struct type that gets returned.
*
* Invoke it with `new` to create a new Buffer instance backing the struct.
* Pass it an existing Buffer instance to use that as the backing buffer.
* Pass in an Object containing the struct fields to auto-populate the
* struct with the data.
*
* @constructor
*/
interface StructType extends ffi.Type {
/** Pass it an existing Buffer instance to use that as the backing buffer. */
new (arg: NodeBuffer, data?: {}): any;
new (data?: {}): any;
/** Pass it an existing Buffer instance to use that as the backing buffer. */
(arg: NodeBuffer, data?: {}): any;
(data?: {}): any;
fields: {[key: string]: {type: ffi.Type}};
/**
* Adds a new field to the struct instance with the given name and type.
* Note that this function will throw an Error if any instances of the struct
* type have already been created, therefore this function must be called at the
* beginning, before any instances are created.
*/
defineProperty(name: string, type: ffi.Type): void;
/**
* Adds a new field to the struct instance with the given name and type.
* Note that this function will throw an Error if any instances of the struct
* type have already been created, therefore this function must be called at the
* beginning, before any instances are created.
*/
defineProperty(name: string, type: string): void;
/**
* Custom for struct type instances.
* @override
*/
toString(): string;
}
/** The struct type meta-constructor. */
var StructType: {
new (fields?: {}): StructType;
new (fields?: any[]): StructType;
(fields?: {}): StructType;
(fields?: any[]): StructType;
}
export = StructType;
}