Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 4 | * 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 | |
| 11 | ndn_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 |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame^] | 18 | (encoder, ndn_BinaryXml_DTag_Action, &forwardingEntry->action))) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 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; |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 28 | if ((error = ndn_BinaryXmlEncoder_writeUnsignedDecimalIntDTagElement |
| 29 | (encoder, ndn_BinaryXml_DTag_ForwardingFlags, |
| 30 | ndn_ForwardingFlags_getForwardingEntryFlags(&forwardingEntry->forwardingFlags)))) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 31 | return error; |
| 32 | if ((error = ndn_BinaryXmlEncoder_writeOptionalUnsignedDecimalIntDTagElement |
| 33 | (encoder, ndn_BinaryXml_DTag_FreshnessSeconds, forwardingEntry->freshnessSeconds))) |
| 34 | return error; |
| 35 | |
| 36 | if ((error = ndn_BinaryXmlEncoder_writeElementClose(encoder))) |
| 37 | return error; |
| 38 | |
| 39 | return NDN_ERROR_success; |
| 40 | } |
| 41 | |
| 42 | ndn_Error ndn_decodeBinaryXmlForwardingEntry(struct ndn_ForwardingEntry *forwardingEntry, struct ndn_BinaryXmlDecoder *decoder) |
| 43 | { |
| 44 | ndn_Error error; |
| 45 | if ((error = ndn_BinaryXmlDecoder_readElementStartDTag(decoder, ndn_BinaryXml_DTag_ForwardingEntry))) |
| 46 | return error; |
| 47 | |
| 48 | if ((error = ndn_BinaryXmlDecoder_readOptionalUDataDTagElement |
Jeff Thompson | 9303453 | 2013-10-08 11:52:43 -0700 | [diff] [blame^] | 49 | (decoder, ndn_BinaryXml_DTag_Action, &forwardingEntry->action))) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 50 | return error; |
| 51 | if ((error = ndn_decodeBinaryXmlName(&forwardingEntry->prefix, decoder))) |
| 52 | return error; |
| 53 | if ((error = ndn_decodeOptionalBinaryXmlPublisherPublicKeyDigest(&forwardingEntry->publisherPublicKeyDigest, decoder))) |
| 54 | return error; |
| 55 | if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement |
| 56 | (decoder, ndn_BinaryXml_DTag_FaceID, &forwardingEntry->faceId))) |
| 57 | return error; |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 58 | |
| 59 | int forwardingEntryFlags; |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 60 | if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 61 | (decoder, ndn_BinaryXml_DTag_ForwardingFlags, &forwardingEntryFlags))) |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 62 | return error; |
Jeff Thompson | 1f8a31a | 2013-09-30 16:18:47 -0700 | [diff] [blame] | 63 | if (forwardingEntryFlags >= 0) |
| 64 | ndn_ForwardingFlags_setForwardingEntryFlags(&forwardingEntry->forwardingFlags, forwardingEntryFlags); |
| 65 | else |
| 66 | // This sets the default flags. |
| 67 | ndn_ForwardingFlags_initialize(&forwardingEntry->forwardingFlags); |
| 68 | |
Jeff Thompson | 990599b | 2013-08-27 15:14:25 -0700 | [diff] [blame] | 69 | if ((error = ndn_BinaryXmlDecoder_readOptionalUnsignedIntegerDTagElement |
| 70 | (decoder, ndn_BinaryXml_DTag_FreshnessSeconds, &forwardingEntry->freshnessSeconds))) |
| 71 | return error; |
| 72 | |
| 73 | if ((error = ndn_BinaryXmlDecoder_readElementClose(decoder))) |
| 74 | return error; |
| 75 | |
| 76 | return NDN_ERROR_success; |
| 77 | } |