"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/ctype/README" (7 Feb 2017, 2890 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 Node-CType is a way to read and write binary data in structured and easy to use
    2 format. Its name comes from the C header file.
    3 
    4 To get started, simply clone the repository or use npm to install it. Once it is
    5 there, simply require it.
    6 
    7 git clone git://github.com/rmustacc/node-ctype
    8 npm install ctype
    9 var mod_ctype = require('ctype')
   10 
   11 
   12 There are two APIs that you can use, depending on what abstraction you'd like.
   13 The low level API let's you read and write individual integers and floats from
   14 buffers. The higher level API let's you read and write structures of these. To
   15 illustrate this, let's looks look at how we would read and write a binary
   16 encoded x,y point.
   17 
   18 In C we would define this structure as follows:
   19 
   20 typedef struct point {
   21 	uint16_t	p_x;
   22 	uint16_t	p_y;
   23 } point_t;
   24 
   25 To read a binary encoded point from a Buffer, we first need to create a CType
   26 parser (where we specify the endian and other options) and add the typedef.
   27 
   28 var parser = new mod_ctype.Parser({ endian: 'big' });
   29 parser.typedef('point_t', [
   30 	{ x: { type: 'uint16_t' } },
   31 	{ y: { type: 'uint16_t' } }
   32 ]);
   33 
   34 From here, given a buffer buf and an offset into it, we can read a point.
   35 
   36 var out = parser.readData([ { point: { type: 'point_t' } } ], buffer, 0);
   37 console.log(out);
   38 { point: { x: 23, y: 42 } }
   39 
   40 Another way to get the same information would be to use the low level methods.
   41 Note that these require you to manually deal with the offset. Here's how we'd
   42 get the same values of x and y from the buffer.
   43 
   44 var x = mod_ctype.ruint16(buf, 'big', 0);
   45 var y = mod_ctype.ruint16(buf, 'big', 2);
   46 console.log(x + ', ' + y);
   47 23, 42
   48 
   49 The true power of this API comes from the ability to define and nest typedefs,
   50 just as you would in C. By default, the following types are defined by default.
   51 Note that they return a Number, unless indicated otherwise.
   52 
   53     * int8_t
   54     * int16_t
   55     * int32_t
   56     * int64_t (returns an array where val[0] << 32 + val[1] would be the value)
   57     * uint8_t
   58     * uint16_t
   59     * uint32_t
   60     * uint64_t (returns an array where val[0] << 32 + val[1] would be the value)
   61     * float
   62     * double
   63     * char (either returns a buffer with that character or a uint8_t)
   64     * char[] (returns an object with the buffer and the number of characters read which is either the total amount requested or until the first 0)
   65 
   66 
   67 ctf2json integration:
   68 
   69 Node-CType supports consuming the output of ctf2json. Once you read in a JSON file,
   70 all you have to do to add all the definitions it contains is:
   71 
   72 var data, parser;
   73 data = JSON.parse(parsedJSONData);
   74 parser = mod_ctype.parseCTF(data, { endian: 'big' });
   75 
   76 For more documentation, see the file README.old. Full documentation is in the
   77 process of being rewritten as a series of manual pages which will be available
   78 in the repository and online for viewing.
   79 
   80 To read the ctio manual page simple run, from the root of the workspace:
   81 
   82 man -Mman -s 3ctype ctio