Source: lp/incoming-face-id.js

  1. /**
  2. * Copyright (C) 2016 Regents of the University of California.
  3. * @author: Jeff Thompson <jefft0@remap.ucla.edu>
  4. * @author: From ndn-cxx fields.hpp https://github.com/named-data/ndn-cxx/blob/master/src/lp/fields.hpp
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. * A copy of the GNU Lesser General Public License is in the file COPYING.
  19. */
  20. /**
  21. * IncomingFaceId represents the incoming face ID header field in an NDNLPv2 packet.
  22. * http://redmine.named-data.net/projects/nfd/wiki/NDNLPv2
  23. * @constructor
  24. */
  25. var IncomingFaceId = function IncomingFaceId()
  26. {
  27. this.faceId_ = null;
  28. };
  29. exports.IncomingFaceId = IncomingFaceId;
  30. /**
  31. * Get the incoming face ID value.
  32. * @return {number} The face ID value.
  33. */
  34. IncomingFaceId.prototype.getFaceId = function() { return this.faceId_; };
  35. /**
  36. * Set the face ID value.
  37. * @param {number} faceId The incoming face ID value.
  38. */
  39. IncomingFaceId.prototype.setFaceId = function(faceId)
  40. {
  41. this.faceId_ = faceId;
  42. };
  43. /**
  44. * Get the first header field in lpPacket which is an IncomingFaceId. This is
  45. * an internal method which the application normally would not use.
  46. * @param {LpPacket} lpPacket The LpPacket with the header fields to search.
  47. * @return {IncomingFaceId} The first IncomingFaceId header field, or null if
  48. * not found.
  49. */
  50. IncomingFaceId.getFirstHeader = function(lpPacket)
  51. {
  52. for (var i = 0; i < lpPacket.countHeaderFields(); ++i) {
  53. var field = lpPacket.getHeaderField(i);
  54. if (field instanceof IncomingFaceId)
  55. return field;
  56. }
  57. return null;
  58. };