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

struct

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

struct - npm Package Compare versions

Comparing version 0.0.5 to 0.0.6

samples/perfTest.js

116

index.js

@@ -1,2 +0,1 @@

function byteField(p, offset) {

@@ -57,12 +56,33 @@ this.length = 1;

}
var
nativeSuff = (signed?'':'U') +'Int'+ (length*8)+ (le?'LE':'BE'),
readMethod = Buffer.prototype['read' + nativeSuff], writeMethod = Buffer.prototype['write' + nativeSuff];
if (!readMethod) {
this.get = function() {
var bor = le ? lec : bec;
return ( signed ? getSVal(bor) : getUVal(bor));
}
}
else {
this.get = function() {
return readMethod.call(p.buf,offset);
};
}
this.get = function() {
var bor = le ? lec : bec;
return ( signed ? getSVal(bor) : getUVal(bor));
if (!writeMethod) {
this.set = function(val) {
var bor = le ? lec : bec;
setVal(bor, val);
}
}
this.set = function(val) {
var bor = le ? lec : bec;
setVal(bor, val);
else {
this.set = function(val){
writeMethod.call(p.buf,val,offset);
}
}
}

@@ -83,2 +103,3 @@

this.set = function(val) {
val += "\0";
if (val.length > length)

@@ -95,4 +116,4 @@ val = val.substring(0, length);

}
this.set = function() {
throw new Error('Cant overwrite Struct');
this.set = function(val) {
struct.set(val);
}

@@ -105,5 +126,2 @@ this.allocate = function() {

function arrayField(p, offset, len, type) {
this.set = function() {
throw new Error('Cant overwrite Array');
}
var as = Struct();

@@ -127,2 +145,5 @@ var args = [].slice.call(arguments, 4);

}
this.set = function(val) {
as.set(val);
}
}

@@ -229,2 +250,3 @@

var beenHere = false;
function applyClosures(p) {

@@ -286,24 +308,41 @@ if (beenHere)

this.set = function(key, val) {
if ( key in priv.fields) {
priv.fields[key].set(val);
} else
throw new Error('Can not find field ' + key);
if (arguments.length == 2) {
if ( key in priv.fields) {
priv.fields[key].set(val);
} else
throw new Error('Can not find field ' + key);
} else if (Buffer.isBuffer(key)) {
this._setBuff(key);
} else {
for (var k in key) {
this.set(k, key[k]);
}
}
}
this.buffer = function() {
return priv.buf;
}
function getFields(){
function getFields() {
var fields = {};
Object.keys(priv.fields).forEach(function(key){
Object.defineProperty(fields,key,{
get: function(){
var res = self.get(key);
if (res instanceof Struct) return res.fields;
else return res;
},
set: function(newVal){
self.set(key,newVal);
},
Object.keys(priv.fields).forEach(function(key) {
var setFunc, getFunc;
if(priv.fields[key] instanceof structField ||
priv.fields[key] instanceof arrayField) {
getFunc = function(){
return priv.fields[key].get().fields;
};
setFunc = function(newVal){
self.set(key, newVal);
};
}
else {
getFunc = priv.fields[key].get;
setFunc = priv.fields[key].set;
};
Object.defineProperty(fields, key, {
get : getFunc,
set : setFunc,
enumerable : true

@@ -314,11 +353,12 @@ });

};
var _fields;
Object.defineProperty(this,'fields',{
get: function(){
if(_fields) return _fields;
return (_fields = getFields());
},
enumerable : true,
configurable : true
Object.defineProperty(this, 'fields', {
get : function() {
if (_fields)
return _fields;
return ( _fields = getFields());
},
enumerable : true,
configurable : true
});

@@ -325,0 +365,0 @@

{ "name" : "struct"
, "version" : "v0.0.5"
, "version" : "v0.0.6"
, "description" : "Pack/Unpack multibyte binary values from/to buffers "

@@ -4,0 +4,0 @@ , "author": "Denys Khanzhiyev"

Struct
======
NodeJS module to work with buffers as structures (or records) of various fields (like c struct declaration, or pascal record).
Uses [node-proxy](https://github.com/samshull/node-proxy).

@@ -6,0 +5,0 @@ Installation

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