Esempio n. 1
0
        /// <summary>
        /// Decode the input and update this Schedule object.
        /// </summary>
        ///
        /// <param name="input"></param>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public void wireDecode(ByteBuffer input)
        {
            // For now, don't use WireFormat and hardcode to use TLV since the encoding
            // doesn't go out over the wire, only into the local SQL database.
            TlvDecoder decoder = new TlvDecoder(input);

            int endOffset = decoder.readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_Schedule);

            // Decode the whiteIntervalList.
            ILOG.J2CsMapping.Collections.Collections.Clear(whiteIntervalList_);
            int listEndOffset = decoder
                                .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_WhiteIntervalList);

            while (decoder.getOffset() < listEndOffset)
            {
                ILOG.J2CsMapping.Collections.Collections.Add(whiteIntervalList_, decodeRepetitiveInterval(decoder));
            }
            decoder.finishNestedTlvs(listEndOffset);

            // Decode the blackIntervalList.
            ILOG.J2CsMapping.Collections.Collections.Clear(blackIntervalList_);
            listEndOffset = decoder
                            .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_BlackIntervalList);
            while (decoder.getOffset() < listEndOffset)
            {
                ILOG.J2CsMapping.Collections.Collections.Add(blackIntervalList_, decodeRepetitiveInterval(decoder));
            }
            decoder.finishNestedTlvs(listEndOffset);

            decoder.finishNestedTlvs(endOffset);
        }
Esempio n. 2
0
        /// <summary>
        /// Decode the input as an NDN-TLV RepetitiveInterval.
        /// </summary>
        ///
        /// <param name="decoder">The decoder with the input to decode.</param>
        /// <returns>A new RepetitiveInterval with the decoded result.</returns>
        private static RepetitiveInterval decodeRepetitiveInterval(
            TlvDecoder decoder)
        {
            int endOffset = decoder
                            .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_RepetitiveInterval);

            // Use Blob to convert UTF8 to a string.
            double startDate = fromIsoString(new Blob(
                                                 decoder.readBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_StartDate), true).toString());
            double endDate = fromIsoString(new Blob(
                                               decoder.readBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_EndDate), true).toString());
            int startHour = (int)decoder
                            .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_IntervalStartHour);
            int endHour = (int)decoder
                          .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_IntervalEndHour);
            int nRepeats = (int)decoder
                           .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_NRepeats);

            int repeatUnitCode = (int)decoder
                                 .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_RepeatUnit);

            RepetitiveInterval.RepeatUnit repeatUnit;
            if (repeatUnitCode == net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.NONE
                .getNumericType())
            {
                repeatUnit = net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.NONE;
            }
            else if (repeatUnitCode == net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY
                     .getNumericType())
            {
                repeatUnit = net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY;
            }
            else if (repeatUnitCode == net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.MONTH
                     .getNumericType())
            {
                repeatUnit = net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.MONTH;
            }
            else if (repeatUnitCode == net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.YEAR
                     .getNumericType())
            {
                repeatUnit = net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.YEAR;
            }
            else
            {
                throw new EncodingException(
                          "Unrecognized RepetitiveInterval RepeatUnit code: "
                          + repeatUnitCode);
            }

            decoder.finishNestedTlvs(endOffset);
            return(new RepetitiveInterval(startDate, endDate, startHour, endHour,
                                          nRepeats, repeatUnit));
        }
        wireDecode(ByteBuffer input)
        {
            clear();

            TlvDecoder decoder   = new TlvDecoder(input);
            int        endOffset = decoder.readNestedTlvsStart(ContentMetaInfo_ContentMetaInfo);

            // Set copy false since we just immediately get a string.
            Blob contentTypeText = new Blob
                                       (decoder.readBlobTlv(ContentMetaInfo_ContentType), false);

            contentType_ = contentTypeText.toString();
            timestamp_   = decoder.readNonNegativeIntegerTlv(ContentMetaInfo_Timestamp);
            hasSegments_ = decoder.readBooleanTlv
                               (ContentMetaInfo_HasSegments, endOffset);
            if (decoder.peekType(ContentMetaInfo_Other, endOffset))
            {
                other_ = new Blob(decoder.readBlobTlv(ContentMetaInfo_Other), true);
            }

            decoder.finishNestedTlvs(endOffset);
        }
Esempio n. 4
0
        /// <summary>
        /// Decode the input as an NDN-TLV SafeBag and update this object.
        /// </summary>
        ///
        /// <param name="input"></param>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public void wireDecode(ByteBuffer input)
        {
            // Decode directly as TLV. We don't support the WireFormat abstraction
            // because this isn't meant to go directly on the wire.
            TlvDecoder decoder   = new TlvDecoder(input);
            int        endOffset = decoder.readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.SafeBag_SafeBag);

            // Get the bytes of the certificate and decode.
            int certificateBeginOffset = decoder.getOffset();
            int certificateEndOffset   = decoder.readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Data);

            decoder.seek(certificateEndOffset);
            certificate_ = new Data();
            certificate_.wireDecode(
                decoder.getSlice(certificateBeginOffset, certificateEndOffset),
                net.named_data.jndn.encoding.TlvWireFormat.get());

            privateKeyBag_ = new Blob(
                decoder.readBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.SafeBag_EncryptedKeyBag), true);

            decoder.finishNestedTlvs(endOffset);
        }