Wentao Shang | bd63e46 | 2012-12-03 16:19:33 -0800 | [diff] [blame] | 1 | /** |
Jeff Thompson | 146d7de | 2012-11-17 16:15:28 -0800 | [diff] [blame] | 2 | * @author: Meki Cheraoui |
Jeff Thompson | 745026e | 2012-10-13 12:49:20 -0700 | [diff] [blame] | 3 | * See COPYING for copyright and distribution information. |
Meki Cherkaoui | f3d8f69 | 2012-05-18 15:44:28 -0700 | [diff] [blame] | 4 | * This class represents Forwarding Entries |
| 5 | */ |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 6 | |
Jeff Thompson | 2b14c7e | 2013-07-29 15:09:56 -0700 | [diff] [blame] | 7 | /** |
| 8 | * Create a new ForwardingEntry with the optional arguments. |
| 9 | * @constructor |
| 10 | * @param {String} action |
| 11 | * @param {Name} prefixName |
| 12 | * @param {PublisherPublicKeyDigest} ccndId |
| 13 | * @param {number} faceID |
| 14 | * @param {number} flags |
| 15 | * @param {number} lifetime in seconds |
| 16 | */ |
| 17 | var ForwardingEntry = function ForwardingEntry(action, prefixName, ccndId, faceID, flags, lifetime) { |
| 18 | this.action = action; |
| 19 | this.prefixName = prefixName; |
| 20 | this.ccndID = ccndId; |
| 21 | this.faceID = faceID; |
| 22 | this.flags = flags; |
| 23 | this.lifetime = lifetime; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 24 | }; |
| 25 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 26 | ForwardingEntry.prototype.from_ccnb =function( |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 27 | //XMLDecoder |
| 28 | decoder) |
| 29 | //throws ContentDecodingException |
| 30 | { |
| 31 | decoder.readStartElement(this.getElementLabel()); |
| 32 | if (decoder.peekStartElement(CCNProtocolDTags.Action)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 33 | this.action = decoder.readUTF8Element(CCNProtocolDTags.Action); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 34 | } |
| 35 | if (decoder.peekStartElement(CCNProtocolDTags.Name)) { |
Jeff Thompson | f3bd359 | 2012-09-29 23:25:30 -0700 | [diff] [blame] | 36 | this.prefixName = new Name(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 37 | this.prefixName.from_ccnb(decoder) ; |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 38 | } |
| 39 | if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) { |
| 40 | this.CcndId = new PublisherPublicKeyDigest(); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 41 | this.CcndId.from_ccnb(decoder); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 42 | } |
| 43 | if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 44 | this.faceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 45 | } |
| 46 | if (decoder.peekStartElement(CCNProtocolDTags.ForwardingFlags)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 47 | this.flags = decoder.readIntegerElement(CCNProtocolDTags.ForwardingFlags); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 48 | } |
| 49 | if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 50 | this.lifetime = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 51 | } |
| 52 | decoder.readEndElement(); |
| 53 | }; |
| 54 | |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 55 | ForwardingEntry.prototype.to_ccnb =function( |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 56 | //XMLEncoder |
| 57 | encoder) |
| 58 | { |
| 59 | |
| 60 | |
| 61 | //if (!validate()) { |
| 62 | //throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing."); |
| 63 | //} |
| 64 | encoder.writeStartElement(this.getElementLabel()); |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 65 | if (null != this.action && this.action.length != 0) |
| 66 | encoder.writeElement(CCNProtocolDTags.Action, this.action); |
| 67 | if (null != this.prefixName) { |
| 68 | this.prefixName.to_ccnb(encoder); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 69 | } |
| 70 | if (null != this.CcndId) { |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 71 | this.CcndId.to_ccnb(encoder); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 72 | } |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 73 | if (null != this.faceID) { |
| 74 | encoder.writeElement(CCNProtocolDTags.FaceID, this.faceID); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 75 | } |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 76 | if (null != this.flags) { |
| 77 | encoder.writeElement(CCNProtocolDTags.ForwardingFlags, this.flags); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 78 | } |
Jeff Thompson | e85ff1d | 2012-09-29 21:21:57 -0700 | [diff] [blame] | 79 | if (null != this.lifetime) { |
| 80 | encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.lifetime); |
Meki Cherkaoui | abb973b | 2012-05-09 14:25:57 -0700 | [diff] [blame] | 81 | } |
| 82 | encoder.writeEndElement(); |
| 83 | }; |
| 84 | |
| 85 | ForwardingEntry.prototype.getElementLabel = function() { return CCNProtocolDTags.ForwardingEntry; } |