blob: 982ef23196647bc22e70ce8a2c05a8f335098a2f [file] [log] [blame]
Jeff Thompson990599b2013-08-27 15:14:25 -07001/**
2 * @author: Jeff Thompson
3 * Derived from ForwardingEntry.js by Meki Cheraoui.
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "binary-xml.h"
8#include "binary-xml-forwarding-entry.h"
9
10ndn_Error ndn_encodeBinaryXmlForwardingEntry(struct ndn_ForwardingEntry *forwardingEntry, struct ndn_BinaryXmlEncoder *encoder)
11{
12 ndn_Error error;
13 if ((error = ndn_BinaryXmlEncoder_writeElementStartDTag(encoder, ndn_BinaryXml_DTag_ForwardingEntry)))
14 return error;
15
16 if ((error = ndn_BinaryXmlEncoder_writeOptionalUDataDTagElement
17 (encoder, ndn_BinaryXml_DTag_Action, forwardingEntry->action, forwardingEntry->actionLength)))
18 return error;
19 if ((error = ndn_encodeBinaryXmlName(&forwardingEntry->prefix, encoder)))
20 return error;
21 // This will skip encoding if there is no publisherPublicKeyDigest.
22 if ((error = ndn_encodeBinaryXmlPublisherPublicKeyDigest(&forwardingEntry->publisherPublicKeyDigest, encoder)))
23 return error;
24 if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
25 (encoder, ndn_BinaryXml_DTag_FaceID, forwardingEntry->faceId)))
26 return error;
27 if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
28 (encoder, ndn_BinaryXml_DTag_ForwardingFlags, forwardingEntry->forwardingFlags)))
29 return error;
30 if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement
31 (encoder, ndn_BinaryXml_DTag_FreshnessSeconds, forwardingEntry->freshnessSeconds)))
32 return error;
33
34 if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder)))
35 return error;
36
37 return NDN_ERROR_success;
38}
39
40ndn_Error ndn_decodeBinaryXmlForwardingEntry(struct ndn_ForwardingEntry *forwardingEntry, struct ndn_BinaryXmlDecoder *decoder)
41{
42 ndn_Error error;
43 if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_ForwardingEntry)))
44 return error;
45
46 if ((error = ndn_BinaryXmlDecoder_readOptionalUDataDTagElement
47 (decoder, ndn_BinaryXml_DTag_Action, &forwardingEntry->action, &forwardingEntry->actionLength)))
48 return error;
49 if ((error = ndn_decodeBinaryXmlName(&forwardingEntry->prefix, decoder)))
50 return error;
51 if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&forwardingEntry->publisherPublicKeyDigest, decoder)))
52 return error;
53 if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
54 (decoder, ndn_BinaryXml_DTag_FaceID, &forwardingEntry->faceId)))
55 return error;
56 if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
57 (decoder, ndn_BinaryXml_DTag_ForwardingFlags, &forwardingEntry->forwardingFlags)))
58 return error;
59 if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement
60 (decoder, ndn_BinaryXml_DTag_FreshnessSeconds, &forwardingEntry->freshnessSeconds)))
61 return error;
62
63 if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder)))
64 return error;
65
66 return NDN_ERROR_success;
67}