blob: baf00cb761f09a1da73037f02e2e83e292c067e2 [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
7var ForwardingEntry = function ForwardingEntry(
8 //ActionType
9 _action,
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070010 //Name
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070011 _prefixName,
12 //PublisherPublicKeyDigest
13 _ccndId,
14 //Integer
15 _faceID,
16 //Integer
17 _flags,
18 //Integer
19 _lifetime){
20
21
22
23 //String
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070024 this.action = _action;
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070025 //Name\
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070026 this.prefixName = _prefixName;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070027 //PublisherPublicKeyDigest
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070028 this.ccndID = _ccndId;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070029 //Integer
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070030 this.faceID = _faceID;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070031 //Integer
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070032 this.flags = _flags;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070033 //Integer
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070034 this.lifetime = _lifetime; // in seconds
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070035
36};
37
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070038ForwardingEntry.prototype.from_ccnb =function(
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070039 //XMLDecoder
40 decoder)
41 //throws ContentDecodingException
42 {
43 decoder.readStartElement(this.getElementLabel());
44 if (decoder.peekStartElement(CCNProtocolDTags.Action)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070045 this.action = decoder.readUTF8Element(CCNProtocolDTags.Action);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070046 }
47 if (decoder.peekStartElement(CCNProtocolDTags.Name)) {
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070048 this.prefixName = new Name();
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070049 this.prefixName.from_ccnb(decoder) ;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070050 }
51 if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) {
52 this.CcndId = new PublisherPublicKeyDigest();
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070053 this.CcndId.from_ccnb(decoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070054 }
55 if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070056 this.faceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070057 }
58 if (decoder.peekStartElement(CCNProtocolDTags.ForwardingFlags)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070059 this.flags = decoder.readIntegerElement(CCNProtocolDTags.ForwardingFlags);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070060 }
61 if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070062 this.lifetime = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070063 }
64 decoder.readEndElement();
65 };
66
67 /**
68 * Used by NetworkObject to encode the object to a network stream.
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070069 */
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070070ForwardingEntry.prototype.to_ccnb =function(
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070071 //XMLEncoder
72encoder)
73{
74
75
76 //if (!validate()) {
77 //throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing.");
78 //}
79 encoder.writeStartElement(this.getElementLabel());
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070080 if (null != this.action && this.action.length != 0)
81 encoder.writeElement(CCNProtocolDTags.Action, this.action);
82 if (null != this.prefixName) {
83 this.prefixName.to_ccnb(encoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070084 }
85 if (null != this.CcndId) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070086 this.CcndId.to_ccnb(encoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070087 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070088 if (null != this.faceID) {
89 encoder.writeElement(CCNProtocolDTags.FaceID, this.faceID);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070090 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070091 if (null != this.flags) {
92 encoder.writeElement(CCNProtocolDTags.ForwardingFlags, this.flags);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070093 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070094 if (null != this.lifetime) {
95 encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.lifetime);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070096 }
97 encoder.writeEndElement();
98 };
99
100ForwardingEntry.prototype.getElementLabel = function() { return CCNProtocolDTags.ForwardingEntry; }