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