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 |
| 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 | |
| 41 | ndn_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 | } |