blob: 60fe750d70fe6feb051c70b64973cc818db086f1 [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,
9 //ContentName
10 _prefixName,
11 //PublisherPublicKeyDigest
12 _ccndId,
13 //Integer
14 _faceID,
15 //Integer
16 _flags,
17 //Integer
18 _lifetime){
19
20
21
22 //String
23 this.Action = _action;
24 //ContentName\
25 this.PrefixName = _prefixName;
26 //PublisherPublicKeyDigest
27 this.CCNID = _ccndId;
28 //Integer
29 this.FaceID = _faceID;
30 //Integer
31 this.Flags = _flags;
32 //Integer
33 this.Lifetime = _lifetime; // in seconds
34
35};
36
37ForwardingEntry.prototype.decode =function(
38 //XMLDecoder
39 decoder)
40 //throws ContentDecodingException
41 {
42 decoder.readStartElement(this.getElementLabel());
43 if (decoder.peekStartElement(CCNProtocolDTags.Action)) {
44 this.Action = decoder.readUTF8Element(CCNProtocolDTags.Action);
45 }
46 if (decoder.peekStartElement(CCNProtocolDTags.Name)) {
47 this.PrefixName = new ContentName();
48 this.PrefixName.decode(decoder) ;
49 }
50 if (decoder.peekStartElement(CCNProtocolDTags.PublisherPublicKeyDigest)) {
51 this.CcndId = new PublisherPublicKeyDigest();
52 this.CcndId.decode(decoder);
53 }
54 if (decoder.peekStartElement(CCNProtocolDTags.FaceID)) {
55 this.FaceID = decoder.readIntegerElement(CCNProtocolDTags.FaceID);
56 }
57 if (decoder.peekStartElement(CCNProtocolDTags.ForwardingFlags)) {
58 this.Flags = decoder.readIntegerElement(CCNProtocolDTags.ForwardingFlags);
59 }
60 if (decoder.peekStartElement(CCNProtocolDTags.FreshnessSeconds)) {
61 this.Lifetime = decoder.readIntegerElement(CCNProtocolDTags.FreshnessSeconds);
62 }
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 */
70ForwardingEntry.prototype.encode =function(
71 //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());
80 if (null != this.Action && this.Action.length != 0)
81 encoder.writeElement(CCNProtocolDTags.Action, this.Action);
82 if (null != this.PrefixName) {
83 this.PrefixName.encode(encoder);
84 }
85 if (null != this.CcndId) {
86 this.CcndId.encode(encoder);
87 }
88 if (null != this.FaceID) {
89 encoder.writeElement(CCNProtocolDTags.FaceID, this.FaceID);
90 }
91 if (null != this.Flags) {
92 encoder.writeElement(CCNProtocolDTags.ForwardingFlags, this.Flags);
93 }
94 if (null != this.Lifetime) {
95 encoder.writeElement(CCNProtocolDTags.FreshnessSeconds, this.Lifetime);
96 }
97 encoder.writeEndElement();
98 };
99
100ForwardingEntry.prototype.getElementLabel = function() { return CCNProtocolDTags.ForwardingEntry; }