blob: 185f784417b6f562611f49ff1d21ac6b56614f98 [file] [log] [blame]
Wentao Shangbd63e462012-12-03 16:19:33 -08001/**
Jeff Thompson146d7de2012-11-17 16:15:28 -08002 * @author: Meki Cheraoui
Jeff Thompson745026e2012-10-13 12:49:20 -07003 * See COPYING for copyright and distribution information.
Meki Cherkaouif3d8f692012-05-18 15:44:28 -07004 * This class represents Forwarding Entries
5 */
Meki Cherkaouiabb973b2012-05-09 14:25:57 -07006
Jeff Thompson2b14c7e2013-07-29 15:09:56 -07007/**
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 */
17var 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 Cherkaouiabb973b2012-05-09 14:25:57 -070024};
25
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070026ForwardingEntry.prototype.from_ccnb =function(
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070027 //XMLDecoder
28 decoder)
29 //throws ContentDecodingException
30 {
31 decoder.readStartElement(this.getElementLabel());
32 if (decoder.peekStartElement(CCNProtocolDTags.Action)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070033 this.action = decoder.readUTF8Element(CCNProtocolDTags.Action);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070034 }
35 if (decoder.peekStartElement(CCNProtocolDTags.Name)) {
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070036 this.prefixName = new Name();
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070037 this.prefixName.from_ccnb(decoder) ;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070038 }
39 if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) {
40 this.CcndId = new PublisherPublicKeyDigest();
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070041 this.CcndId.from_ccnb(decoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070042 }
43 if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070044 this.faceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070045 }
46 if (decoder.peekStartElement(CCNProtocolDTags.ForwardingFlags)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070047 this.flags = decoder.readIntegerElement(CCNProtocolDTags.ForwardingFlags);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070048 }
49 if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070050 this.lifetime = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070051 }
52 decoder.readEndElement();
53 };
54
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070055ForwardingEntry.prototype.to_ccnb =function(
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070056 //XMLEncoder
57encoder)
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 Thompsone85ff1d2012-09-29 21:21:57 -070065 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 Cherkaouiabb973b2012-05-09 14:25:57 -070069 }
70 if (null != this.CcndId) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070071 this.CcndId.to_ccnb(encoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070072 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070073 if (null != this.faceID) {
74 encoder.writeElement(CCNProtocolDTags.FaceID, this.faceID);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070075 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070076 if (null != this.flags) {
77 encoder.writeElement(CCNProtocolDTags.ForwardingFlags, this.flags);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070078 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070079 if (null != this.lifetime) {
80 encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.lifetime);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070081 }
82 encoder.writeEndElement();
83 };
84
85ForwardingEntry.prototype.getElementLabel = function() { return CCNProtocolDTags.ForwardingEntry; }