blob: a095516b0c6ca623bc78065a6d53d8c06b3b303a [file] [log] [blame]
Meki Cherkaouif3d8f692012-05-18 15:44:28 -07001/*
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.
69 * @see org.ccnx.ccn.impl.encoding.XMLEncodable
70 */
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070071ForwardingEntry.prototype.to_ccnb =function(
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070072 //XMLEncoder
73encoder)
74{
75
76
77 //if (!validate()) {
78 //throw new ContentEncodingException("Cannot encode " + this.getClass().getName() + ": field values missing.");
79 //}
80 encoder.writeStartElement(this.getElementLabel());
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070081 if (null != this.action && this.action.length != 0)
82 encoder.writeElement(CCNProtocolDTags.Action, this.action);
83 if (null != this.prefixName) {
84 this.prefixName.to_ccnb(encoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070085 }
86 if (null != this.CcndId) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070087 this.CcndId.to_ccnb(encoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070088 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070089 if (null != this.faceID) {
90 encoder.writeElement(CCNProtocolDTags.FaceID, this.faceID);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070091 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070092 if (null != this.flags) {
93 encoder.writeElement(CCNProtocolDTags.ForwardingFlags, this.flags);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070094 }
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070095 if (null != this.lifetime) {
96 encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.lifetime);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070097 }
98 encoder.writeEndElement();
99 };
100
101ForwardingEntry.prototype.getElementLabel = function() { return CCNProtocolDTags.ForwardingEntry; }