[Ndn-lib] ndn-js: Changed the return type of Name.getValue(), etc.

Thompson, Jeff jefft0 at remap.ucla.edu
Wed Jun 25 18:28:22 PDT 2014


Hello all,

The NDN JavaScript client library ndn-js version v0.4 was released on June 18.
https://github.com/named-data/ndn-js/releases/tag/v0.4

If you get the latest code from GitHub, there are some changes to make ndn-js conform to the NDN Common Client Libraries API as documented here:
http://named-data.net/doc/ndn-ccl-api/

Specifically, the return type is changed for the following methods. If these changes cause unexpected behavior in your application, you can revert to NDN-JS version v0.4 while updating your application.

  *     Changed Name.Component.getValue() to return a Blob, not Buffer. If you need the former behavior, call the deprecated method getValueAsBuffer().
  *     Changed Interest.getNonce() to return a Blob, not Buffer. If you need the former behavior, call the deprecated method getNonceAsBuffer().
  *     Changed Data.getContent() to return a Blob, not Buffer. If you need the former behavior, call the deprecated method getContentAsBuffer().
  *     Changed Signature.getSignature() to return a Blob, not Buffer. If you need the former behavior, call the deprecated method getSignatureAsBuffer().
  *     Changed KeyLocator.getKeyData() to return a Blob, not Buffer. If you need the former behavior, call the deprecated method getKeyDataAsBuffer().
  *     Changed MetaInfo.getFinalBlockID() to return a Name.Component, not Buffer. If you need the former behavior, call the deprecated method getFinalBlockIDAsBuffer().

For example, in ndn-js version v0.4, the following worked because name.get(0).getValue() returns a Buffer:

    name.get(0).getValue().length

But now, getValue() returns a Blob:
http://named-data.net/doc/ndn-ccl-api/blob.html

To fix this code, you can either change to use the Blob methods (preferred):

    name.get(0).getValue().size()

Or, you can simply change getValue to the deprecated getValueAsBuffer which returns the same Buffer that getValue did in version 0.4:

    name.get(0).getValueAsBuffer().length

These deprecated methods are there to help you transition your code, but will be removed in the future. (We will announce.)

Also, the direct use of object fields is deprecated. You should use get/set methods.  For example, your code may have:

    var message = "Received an interest with name " + interest.name.toUri()

You should change to use the Common Client Libraries API:

    var message = "Received an interest with name " + interest.getName().toUri()
http://named-data.net/doc/ndn-ccl-api/interest.html#interest-getname-method

You should use the get/set methods instead of the object's internal fields because the types and names of the internal fields will change in the future, but the get/set API will remain.

Thank you,
- Jeff T
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.lists.cs.ucla.edu/pipermail/ndn-lib/attachments/20140626/cbc624aa/attachment.html>


More information about the Ndn-lib mailing list