blob: f0314d7d98a9b7ae9ea340ab465204c4b7450970 [file] [log] [blame]
Meki Cherkaouif3d8f692012-05-18 15:44:28 -07001/*
2 * @author: ucla-cs
3 * This class represents Forwarding Entries
4 */
Meki Cherkaouiabb973b2012-05-09 14:25:57 -07005
6var ForwardingEntry = function ForwardingEntry(
7 //ActionType
8 _action,
Jeff Thompsonf3bd3592012-09-29 23:25:30 -07009 //Name
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070010 _prefixName,
11 //PublisherPublicKeyDigest
12 _ccndId,
13 //Integer
14 _faceID,
15 //Integer
16 _flags,
17 //Integer
18 _lifetime){
19
20
21
22 //String
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070023 this.action = _action;
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070024 //Name\
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070025 this.prefixName = _prefixName;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070026 //PublisherPublicKeyDigest
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070027 this.ccndID = _ccndId;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070028 //Integer
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070029 this.faceID = _faceID;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070030 //Integer
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070031 this.flags = _flags;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070032 //Integer
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070033 this.lifetime = _lifetime; // in seconds
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070034
35};
36
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070037ForwardingEntry.prototype.from_ccnb =function(
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070038 //XMLDecoder
39 decoder)
40 //throws ContentDecodingException
41 {
42 decoder.readStartElement(this.getElementLabel());
43 if (decoder.peekStartElement(CCNProtocolDTags.Action)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070044 this.action = decoder.readUTF8Element(CCNProtocolDTags.Action);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070045 }
46 if (decoder.peekStartElement(CCNProtocolDTags.Name)) {
Jeff Thompsonf3bd3592012-09-29 23:25:30 -070047 this.prefixName = new Name();
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070048 this.prefixName.from_ccnb(decoder) ;
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070049 }
50 if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) {
51 this.CcndId = new PublisherPublicKeyDigest();
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070052 this.CcndId.from_ccnb(decoder);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070053 }
54 if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070055 this.faceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070056 }
57 if (decoder.peekStartElement(CCNProtocolDTags.ForwardingFlags)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070058 this.flags = decoder.readIntegerElement(CCNProtocolDTags.ForwardingFlags);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070059 }
60 if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) {
Jeff Thompsone85ff1d2012-09-29 21:21:57 -070061 this.lifetime = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds);
Meki Cherkaouiabb973b2012-05-09 14:25:57 -070062 }
63 decoder.readEndElement();
64 };
65
66 /**
67 * Used by NetworkObject to encode the object to a network stream.
68 * @see org.ccnx.ccn.impl.encoding.XMLEncodable
69 */
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; }