当前位置: 首页>>代码示例>>C#>>正文


C# Interest.getSelectedDelegationIndex方法代码示例

本文整理汇总了C#中net.named_data.jndn.Interest.getSelectedDelegationIndex方法的典型用法代码示例。如果您正苦于以下问题:C# Interest.getSelectedDelegationIndex方法的具体用法?C# Interest.getSelectedDelegationIndex怎么用?C# Interest.getSelectedDelegationIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.named_data.jndn.Interest的用法示例。


在下文中一共展示了Interest.getSelectedDelegationIndex方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: testInterestSelectedDelegation

        public void testInterestSelectedDelegation()
        {
            Link link = new Link();
            link.setName(new Name("test"));
            link.addDelegation(10, new Name("/test1"));
            link.addDelegation(20, new Name("/test2"));
            link.addDelegation(100, new Name("/test3"));

            try {
                keyChain.sign(link, certificateName);
            } catch (SecurityException ex) {
                Assert.Fail(ex.Message);
            }

            Blob linkEncoding = link.wireEncode();

            Interest interestA = new Interest();
            interestA.setLinkWireEncoding(linkEncoding);
            Assert.AssertTrue(interestA.getSelectedDelegationIndex() < 0);

            interestA.setSelectedDelegationIndex(link.getDelegations().find(
                    new Name("test2")));
            Assert.AssertTrue(interestA.getSelectedDelegationIndex() >= 0);
            Link link2 = null;
            try {
                link2 = interestA.getLink();
            } catch (Exception ex_0) {
                Assert.Fail(ex_0.Message);
            }
            Assert.AssertEquals(
                    new Name("test2"),
                    link2.getDelegations()
                            .get(interestA.getSelectedDelegationIndex()).getName());

            interestA.setSelectedDelegationIndex(-1);
            Assert.AssertTrue(interestA.getSelectedDelegationIndex() < 0);
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:37,代码来源:TestLink.cs

示例2: testDecodeInterestWithLinkNonDecreasingOrder

        public void testDecodeInterestWithLinkNonDecreasingOrder()
        {
            Interest interest = new Interest();

            Link link = null;
            try {
                interest.wireDecode(new Blob(InterestWithLinkNonDecreasingOrder,
                        false));
                link = interest.getLink();
            } catch (Exception ex) {
                Assert.Fail("Decoding InterestWithLinkNonDecreasingOrder: "
                        + ex.Message);
            }
            Assert.AssertTrue(interest.getSelectedDelegationIndex() >= 0);
            Assert.AssertEquals(new Name("ndn"),
                    link.getDelegations()
                            .get(interest.getSelectedDelegationIndex()).getName());
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:18,代码来源:TestLink.cs

示例3: encodeInterest

        /// <summary>
        /// Encode interest using NDN-TLV and return the encoding.
        /// </summary>
        ///
        /// <param name="interest">The Interest object to encode.</param>
        /// <param name="signedPortionBeginOffset">name component and ends just before the final name component (which is assumed to be a signature for a signed interest).</param>
        /// <param name="signedPortionEndOffset">name component and ends just before the final name component (which is assumed to be a signature for a signed interest).</param>
        /// <returns>A Blob containing the encoding.</returns>
        public override Blob encodeInterest(Interest interest,
				int[] signedPortionBeginOffset, int[] signedPortionEndOffset)
        {
            TlvEncoder encoder = new TlvEncoder();
            int saveLength = encoder.getLength();

            // Encode backwards.
            encoder.writeOptionalNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.SelectedDelegation,
                    interest.getSelectedDelegationIndex());
            try {
                Blob linkWireEncoding = interest.getLinkWireEncoding(this);
                if (!linkWireEncoding.isNull())
                    // Encode the entire link as is.
                    encoder.writeBuffer(linkWireEncoding.buf());
            } catch (EncodingException ex) {
                throw new Exception(ex.Message);
            }

            encoder.writeOptionalNonNegativeIntegerTlvFromDouble(
                    net.named_data.jndn.encoding.tlv.Tlv.InterestLifetime,
                    interest.getInterestLifetimeMilliseconds());

            // Encode the Nonce as 4 bytes.
            if (interest.getNonce().size() == 0) {
                // This is the most common case. Generate a nonce.
                ByteBuffer nonce = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(4);
                random_.nextBytes(nonce.array());
                encoder.writeBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.Nonce, nonce);
            } else if (interest.getNonce().size() < 4) {
                ByteBuffer nonce_0 = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(4);
                // Copy existing nonce bytes.
                nonce_0.put(interest.getNonce().buf());

                // Generate random bytes for remaining bytes in the nonce.
                for (int i = 0; i < 4 - interest.getNonce().size(); ++i)
                    nonce_0.put((byte) random_.Next());

                nonce_0.flip();
                encoder.writeBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.Nonce, nonce_0);
            } else if (interest.getNonce().size() == 4)
                // Use the nonce as-is.
                encoder.writeBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.Nonce, interest.getNonce().buf());
            else {
                // Truncate.
                ByteBuffer nonce_1 = interest.getNonce().buf();
                // buf() returns a new ByteBuffer, so we can change its limit.
                nonce_1.limit(nonce_1.position() + 4);
                encoder.writeBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.Nonce, nonce_1);
            }

            encodeSelectors(interest, encoder);
            int[] tempSignedPortionBeginOffset = new int[1];
            int[] tempSignedPortionEndOffset = new int[1];
            encodeName(interest.getName(), tempSignedPortionBeginOffset,
                    tempSignedPortionEndOffset, encoder);
            int signedPortionBeginOffsetFromBack = encoder.getLength()
                    - tempSignedPortionBeginOffset[0];
            int signedPortionEndOffsetFromBack = encoder.getLength()
                    - tempSignedPortionEndOffset[0];

            encoder.writeTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.Interest, encoder.getLength()
                    - saveLength);
            signedPortionBeginOffset[0] = encoder.getLength()
                    - signedPortionBeginOffsetFromBack;
            signedPortionEndOffset[0] = encoder.getLength()
                    - signedPortionEndOffsetFromBack;

            return new Blob(encoder.getOutput(), false);
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:77,代码来源:Tlv0_2WireFormat.cs

示例4: testDecodeInterestWithLink

        public void testDecodeInterestWithLink()
        {
            Interest interest = new Interest();
            Link link = null;
            try {
                interest.wireDecode(new Blob(InterestWithLink, false));
                link = interest.getLink();
            } catch (Exception ex) {
                Assert.Fail("Decoding InterestWithLink: " + ex.Message);
            }

            Assert.AssertTrue("Interest link object not specified", link != null);
            Assert.AssertEquals(new Name("/local/ndn/prefix"), link.getName());

            DelegationSet delegations = link.getDelegations();
            for (int i = 0; i < delegations.size(); ++i) {
                if (i == 0) {
                    Assert.AssertEquals(10, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("local"), delegations.get(i).getName());
                }
                if (i == 1) {
                    Assert.AssertEquals(20, delegations.get(i).getPreference());
                    Assert.AssertEquals(new Name("ndn"), delegations.get(i).getName());
                }
            }

            Assert.AssertTrue("Interest selected delegation not specified",
                    interest.getSelectedDelegationIndex() >= 0);
            Assert.AssertEquals(new Name("local"),
                    delegations.get(interest.getSelectedDelegationIndex())
                            .getName());
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:32,代码来源:TestLink.cs

示例5: decodeInterest

        /// <summary>
        /// Decode input as an interest in  NDN-TLV and set the fields of the interest
        /// object.
        /// </summary>
        ///
        /// <param name="interest">The Interest object whose fields are updated.</param>
        /// <param name="input"></param>
        /// <param name="signedPortionBeginOffset">name component and ends just before the final name component (which is assumed to be a signature for a signed interest).</param>
        /// <param name="signedPortionEndOffset">name component and ends just before the final name component (which is assumed to be a signature for a signed interest).</param>
        /// <param name="copy">unchanged while the Blob values are used.</param>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public override void decodeInterest(Interest interest, ByteBuffer input,
				int[] signedPortionBeginOffset, int[] signedPortionEndOffset,
				bool copy)
        {
            TlvDecoder decoder = new TlvDecoder(input);

            int endOffset = decoder.readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Interest);
            decodeName(interest.getName(), signedPortionBeginOffset,
                    signedPortionEndOffset, decoder, copy);
            if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.Selectors, endOffset))
                decodeSelectors(interest, decoder, copy);
            // Require a Nonce, but don't force it to be 4 bytes.
            ByteBuffer nonce = decoder.readBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.Nonce);
            interest.setInterestLifetimeMilliseconds(decoder
                    .readOptionalNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.InterestLifetime,
                            endOffset));

            if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.Data, endOffset)) {
                // Get the bytes of the Link TLV.
                int linkBeginOffset = decoder.getOffset();
                int linkEndOffset = decoder.readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Data);
                decoder.seek(linkEndOffset);

                interest.setLinkWireEncoding(
                        new Blob(decoder.getSlice(linkBeginOffset, linkEndOffset),
                                copy), this);
            } else
                interest.unsetLink();
            interest.setSelectedDelegationIndex((int) decoder
                    .readOptionalNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.SelectedDelegation,
                            endOffset));
            if (interest.getSelectedDelegationIndex() >= 0 && !interest.hasLink())
                throw new EncodingException(
                        "Interest has a selected delegation, but no link object");

            // Set the nonce last because setting other interest fields clears it.
            interest.setNonce(new Blob(nonce, copy));

            decoder.finishNestedTlvs(endOffset);
        }
开发者ID:named-data,项目名称:ndn-dot-net,代码行数:51,代码来源:Tlv0_2WireFormat.cs


注:本文中的net.named_data.jndn.Interest.getSelectedDelegationIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。