/// <summary> /// Create a new MetaInfo with a copy of the fields in the given metaInfo. /// </summary> /// /// <param name="metaInfo">The MetaInfo to copy.</param> public MetaInfo(MetaInfo metaInfo) { this.type_ = net.named_data.jndn.ContentType.BLOB; this.otherTypeCode_ = -1; this.freshnessPeriod_ = -1; this.finalBlockId_ = new Name.Component(); this.changeCount_ = 0; type_ = metaInfo.type_; freshnessPeriod_ = metaInfo.freshnessPeriod_; // Name.Component is read-only, so we don't need a deep copy. finalBlockId_ = metaInfo.finalBlockId_; }
/// <summary> /// Set metaInfo to a copy of the given MetaInfo. /// </summary> /// /// <param name="metaInfo">The MetaInfo which is copied.</param> /// <returns>This Data so that you can chain calls to update values.</returns> public Data setMetaInfo(MetaInfo metaInfo) { metaInfo_.set((metaInfo == null) ? new MetaInfo() : new MetaInfo(metaInfo)); ++changeCount_; return this; }
private static void decodeMetaInfo(MetaInfo metaInfo, TlvDecoder decoder, bool copy) { int endOffset = decoder.readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.MetaInfo); // The ContentType enum is set up with the correct integer for each // NDN-TLV ContentType. int type = (int) decoder.readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.ContentType, endOffset); if (type < 0 || type == net.named_data.jndn.ContentType.BLOB.getNumericType()) // Default to BLOB if the value is omitted. metaInfo.setType(net.named_data.jndn.ContentType.BLOB); else if (type == net.named_data.jndn.ContentType.LINK.getNumericType()) metaInfo.setType(net.named_data.jndn.ContentType.LINK); else if (type == net.named_data.jndn.ContentType.KEY.getNumericType()) metaInfo.setType(net.named_data.jndn.ContentType.KEY); else if (type == net.named_data.jndn.ContentType.NACK.getNumericType()) metaInfo.setType(net.named_data.jndn.ContentType.NACK); else { // Unrecognized content type. metaInfo.setType(net.named_data.jndn.ContentType.OTHER_CODE); metaInfo.setOtherTypeCode(type); } metaInfo.setFreshnessPeriod(decoder.readOptionalNonNegativeIntegerTlv( net.named_data.jndn.encoding.tlv.Tlv.FreshnessPeriod, endOffset)); if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.FinalBlockId, endOffset)) { int finalBlockIdEndOffset = decoder .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.FinalBlockId); metaInfo.setFinalBlockId(decodeNameComponent(decoder, copy)); decoder.finishNestedTlvs(finalBlockIdEndOffset); } else metaInfo.setFinalBlockId(null); decoder.finishNestedTlvs(endOffset); }
private static void encodeMetaInfo(MetaInfo metaInfo, TlvEncoder encoder) { int saveLength = encoder.getLength(); // Encode backwards. ByteBuffer finalBlockIdBuf = metaInfo.getFinalBlockId().getValue() .buf(); if (finalBlockIdBuf != null && finalBlockIdBuf.remaining() > 0) { // FinalBlockId has an inner NameComponent. int finalBlockIdSaveLength = encoder.getLength(); encodeNameComponent(metaInfo.getFinalBlockId(), encoder); encoder.writeTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.FinalBlockId, encoder.getLength() - finalBlockIdSaveLength); } encoder.writeOptionalNonNegativeIntegerTlvFromDouble( net.named_data.jndn.encoding.tlv.Tlv.FreshnessPeriod, metaInfo.getFreshnessPeriod()); if (!(metaInfo.getType() == net.named_data.jndn.ContentType.BLOB)) { // Not the default, so we need to encode the type. if (metaInfo.getType() == net.named_data.jndn.ContentType.LINK || metaInfo.getType() == net.named_data.jndn.ContentType.KEY || metaInfo.getType() == net.named_data.jndn.ContentType.NACK) // The ContentType enum is set up with the correct integer for // each NDN-TLV ContentType. encoder.writeNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ContentType, metaInfo .getType().getNumericType()); else if (metaInfo.getType() == net.named_data.jndn.ContentType.OTHER_CODE) encoder.writeNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.ContentType, metaInfo.getOtherTypeCode()); else // We don't expect this to happen. throw new Exception("unrecognized TLV ContentType"); } encoder.writeTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.MetaInfo, encoder.getLength() - saveLength); }