Coder Social home page Coder Social logo

Comments (6)

dcousens avatar dcousens commented on September 27, 2024 1

@JKRhb please see #22 for your answer 👍

from coap-packet.

digitallyrefreshed avatar digitallyrefreshed commented on September 27, 2024

I forgot to mention that the same goes for optionStringToNumber:

var optionStringToNumber = (function genOptionParser() {

 var code = Object.keys(numMap).reduce(function(acc, key) {

   acc += 'case \'' + numMap[key] + '\':\n'
   acc += '  return \'' + key +'\'\n'

   return acc
 }, 'switch(string) {\n')

 code += 'default:\n'
 code += 'return parseInt(string)'
 code += '}\n'

 return new Function('string', code)
})()

can be replaced with:

var optionStringToNumber = function(string){
  for (var key in numMap){
    if (numMap.hasOwnProperty(key)){
      if (numMap[key] == string){
        return key;
      }
    }
  }
  return parseInt(string);
}

from coap-packet.

mcollina avatar mcollina commented on September 27, 2024

First, I'm very happy to see this used in the browser too!
(Have you tried porting node-coap too?)

Anyway, that technique was used because it's way faster than yours, and in something which is likely used as a server component (like this one) is important.
Are you using Browserify, right? In case, we can move that function into another file, and use the 'browser' field to let browserify pick the correct one.
Would you like to submit a PR that implements that behavior?

from coap-packet.

digitallyrefreshed avatar digitallyrefreshed commented on September 27, 2024

Yeah, I'm using browserify. node-coap is working fine now. I had to find suitable browserify or chrome ported version of dgram. The current version of dgram I use (chrome-dgram) does not (yet) support IPv6 so I had to comment out anything to do with IPv6. Other than that it's working.

Gotcha. Makes sense.

Sure, I'll submit a PR and and add my "fixes" there.

from coap-packet.

mcollina avatar mcollina commented on September 27, 2024

Plus, if you can make it 'safe' to (not) crash when ipv6 is missing it will be great!

from coap-packet.

JKRhb avatar JKRhb commented on September 27, 2024

Revisiting the functions in question I was wondering if creating a switch statement like this is still considered faster or if the use of object literals has catched up in the meantime.

from coap-packet.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.