Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ctype

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ctype - npm Package Compare versions

Comparing version 0.2.1 to 0.3.0

tst/ctype/tst.char.js

70

ctype.js

@@ -220,5 +220,4 @@ /*

/*
* Construct a per parser specific set of the basic types. That way if this is
* modified, it's okay. The values themselves should never be modified; however,
* the set of keys may change over time.
* Each parser has their own set of types. We want to make sure that they each
* get their own copy as they may need to modify it.
*/

@@ -351,3 +350,4 @@ function ctGetBasicTypes()

* Create a new instance of the parser. Each parser has its own store of
* typedefs and endianness. Conf is an object with the following values:
* typedefs and endianness. Conf is an object with the following required
* values:
*

@@ -357,7 +357,12 @@ * endian Either 'big' or 'little' do determine the endianness we

*
* And the following optional values:
*
* char-type Valid options here are uint8 and int8. If uint8 is
* specified this changes the default behavior of a single
* char from being a buffer of a single character to being
* a uint8_t. If int8, it becomes an int8_t instead.
*/
function CTypeParser(conf)
{
if (!conf)
throw (new Error('missing required argument'));
if (!conf) throw (new Error('missing required argument'));

@@ -370,4 +375,19 @@ if (!('endian' in conf))

if ('char-type' in conf && (conf['char-type'] != 'uint8' &&
conf['char-type'] != 'int8'))
throw (new Error('invalid option for char-type: ' +
conf['char-type']));
this.endian = conf['endian'];
this.types = ctGetBasicTypes();
/*
* This may be a more graceful way to do this, but this will have to
* serve.
*/
if ('char-type' in conf && conf['char-type'] == 'uint8')
this.types['char'] = this.types['uint8_t'];
if ('char-type' in conf && conf['char-type'] == 'int8')
this.types['char'] = this.types['int8_t'];
}

@@ -525,3 +545,3 @@

else if (dispatch == 'write')
return (this.writeStruct(value, this.types[type],
return (this.readStruct(value, this.types[type],
buffer, offset));

@@ -562,3 +582,3 @@ else

if (type['type'] == 'char')
parse = deftypes['char[]']['read'](len,
parse = this.types['char[]']['read'](len,
this.endian, buffer, offset);

@@ -570,3 +590,3 @@ else

if (type['type'] in deftypes)
parse = deftypes[type['type']]['read'](this.endian,
parse = this.types[type['type']]['read'](this.endian,
buffer, offset);

@@ -650,7 +670,7 @@ else

if (buffer === undefined)
throw (new Error('missing buffer for what we should be' +
throw (new Error('missing buffer for what we should be ' +
'parsing'));
if (offset === undefined)
throw (new Error('missing offset for what we should be' +
throw (new Error('missing offset for what we should be ' +
'parsing'));

@@ -700,10 +720,10 @@

if (type['type'] == 'char')
ret = deftypes['char[]']['write'](value, len,
ret = this.types['char[]']['write'](value, len,
this.endian, buffer, offset);
else
ret = this.writeArray(value, type['type'],
buffer, offset);
len, buffer, offset);
} else {
if (type['type'] in deftypes)
ret = deftypes[type['type']]['write'](value,
ret = this.types[type['type']]['write'](value,
this.endian, buffer, offset);

@@ -721,3 +741,3 @@ else

*/
CTypeParser.prototype.writeStruct = function (value, def, buffer, offset)
CTypeParser.prototype.writeStruct = function (def, buffer, offset)
{

@@ -737,5 +757,5 @@ var ii, entry, type, key;

offset += this.writeEntry(value[ii], type, buffer, offset);
offset += this.writeEntry(entry['value'], type, buffer, offset);
/* Keep track of types for array length resolution */
/* Now that we've written it out, we can use it for arrays */
vals[key] = entry['value'];

@@ -755,9 +775,5 @@ }

* offset The offset in the buffer to write to
*
* TODO This endpoint really is just awful. See ticket CTYPE-6
*/
CTypeParser.prototype.writeData = function (def, buffer, offset)
{
var ii, vals, key;
if (def === undefined)

@@ -768,16 +784,12 @@ throw (new Error('missing definition for what we should be' +

if (buffer === undefined)
throw (new Error('missing buffer for what we should be' +
throw (new Error('missing buffer for what we should be ' +
'parsing'));
if (offset === undefined)
throw (new Error('missing offset for what we should be' +
throw (new Error('missing offset for what we should be ' +
'parsing'));
ctCheckReq(def, this.types, [ 'value' ]);
vals = [];
for (ii = 0; ii < def.length; ii++) {
key = Object.keys(def[ii])[0];
vals.push(def[ii][key]['value']);
}
this.writeStruct(vals, def, buffer, offset);
this.writeStruct(def, buffer, offset);
};

@@ -784,0 +796,0 @@

{
"name": "ctype",
"version": "0.2.1",
"version": "0.3.0",
"description": "read and write binary structures and data types",

@@ -5,0 +5,0 @@ "homepage": "https://github.com/rmustacc/node-ctype",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc