public static IEnumerable <Frame> GetFramesOf(this IMetadataDecoder decoder, SequenceHolder holder, CancellationToken token = default)
        {
            if (token == default)
            {
                token = CancellationToken.None;
            }
            while (!token.IsCancellationRequested)
            {
                var buffer = holder.Buffer;
                var reader = new SequenceReader <byte>(buffer);
                if (!decoder.TryParse(ref reader, out var metadata))
                {
                    break;
                }
                if (metadata.Length < 0)
                {
                    throw new ArgumentOutOfRangeException(
                              nameof(metadata.Length), string.Format(_error, metadata));
                }

                if (reader.Remaining < metadata.Length)
                {
                    break;
                }
                var payload = buffer.Slice(reader.Position, metadata.Length);
                yield return(new Frame(payload, metadata));

                holder.Buffer = buffer.Slice(payload.End);
            }
        }
コード例 #2
0
    public void Init(SequenceHolder _sequenceHolder)
    {
        if (_sequenceHolder == null || editorWindow != null)
        {
            Destroy(gameObject);
        }
        else
        {
            editorWindow = this;
        }

        sequenceHolder = _sequenceHolder;

        sequence = sequenceHolder.GetSequence();

        sequenceVisualization = new List <Image>();

        foreach (bool slot in sequence)
        {
            GameObject t = new GameObject("slot", typeof(RectTransform));
            Image      i = t.AddComponent <Image>();
            i.sprite = slot ? on : off;
            t.transform.SetParent(sequenceParent);
            if (i != null)
            {
                sequenceVisualization.Add(i);
            }
        }

        highlightTargetPos = sequenceParent.position;

        Time.timeScale = 0;
    }
コード例 #3
0
            /// <summary>
            /// Adds the specified sequence with position.
            /// </summary>
            /// <param name="position">Position of the sequence in file.</param>
            /// <param name="sequence">Sequence to cache.</param>
            public void Add(long position, ISequence sequence)
            {
                if (this.Count == 0)
                {
                    this.sequenceLength = (int)sequence.Count;
                }

                int            index     = (int)(position / (sequenceLength * bucketSize));
                SequenceHolder newHolder = new SequenceHolder()
                {
                    Position = position, Sequence = sequence
                };

                if (index >= buckets.Count)
                {
                    while (index >= buckets.Count)
                    {
                        buckets.Add(null);
                    }

                    buckets[index] = newHolder;
                    this.Count++;
                    return;
                }

                SequenceHolder holder = buckets[index];

                if (holder == null)
                {
                    buckets[index] = newHolder;
                    this.Count++;
                    return;
                }

                if (holder.Position > position)
                {
                    buckets[index]      = newHolder;
                    buckets[index].Next = holder;
                }
                else
                {
                    while (holder.Next != null)
                    {
                        if (holder.Next.Position > position)
                        {
                            break;
                        }

                        holder = holder.Next;
                    }

                    newHolder.Next = holder.Next;
                    holder.Next    = newHolder;
                }

                this.Count++;
            }
コード例 #4
0
        public void GetFramesOf_ShouldBreak_OnOneAndHalfFrame()
        {
            var buffer = FrameProvider.GetMultiplesRandom(5, 4, 6).Slice(0, 14);
            var holder = new SequenceHolder(buffer);
            var frames = _decoder.GetFramesOf(holder)
                         .ToArray();

            Assert.Single(frames);
            Assert.Equal(buffer.GetPosition(10), holder.Buffer.Start);
        }
コード例 #5
0
        public void GetFramesOf_ShouldBreak_OnValidButIncompletePayload()
        {
            Memory <byte> buffer = new byte[16];

            BinaryPrimitives.WriteInt16BigEndian(buffer.Span, 5);
            BinaryPrimitives.WriteInt32BigEndian(buffer.Span.Slice(2), 16);
            var holder = new SequenceHolder(new ReadOnlySequence <byte>(buffer));
            var frames = _decoder.GetFramesOf(holder)
                         .ToArray();

            Assert.Empty(frames);
        }
コード例 #6
0
            /// <summary>
            /// Gets all sequences present in this instance.
            /// </summary>
            public IEnumerable <ISequence> GetAllSequences()
            {
                for (int i = 0; i < buckets.Count; i++)
                {
                    SequenceHolder holder = buckets[i];
                    while (holder != null)
                    {
                        yield return(holder.Sequence);

                        holder = holder.Next;
                    }
                }
            }
コード例 #7
0
            /// <summary>
            /// Gets the sequence for the specified position.
            /// </summary>
            /// <param name="position">Position.</param>
            public ISequence GetSequenceAt(long position)
            {
                int index = (int)(position / (sequenceLength * bucketSize));

                if (index >= buckets.Count)
                {
                    return(null);
                }

                SequenceHolder holder = buckets[index];

                while (holder != null)
                {
                    if (holder.Position == position)
                    {
                        return(holder.Sequence);
                    }

                    holder = holder.Next;
                }

                return(null);
            }
コード例 #8
0
    private void Edit(SequenceHolder sequenceHolder)
    {
        SequenceEditor sequenceEditor = Instantiate(sequenceEditorPrefab, transform.position, Quaternion.identity).GetComponent <SequenceEditor>();

        sequenceEditor.Init(sequenceHolder);
    }
コード例 #9
0
            /// <summary>
            /// Adds the specified sequence with position.
            /// </summary>
            /// <param name="position">Position of the sequence in file.</param>
            /// <param name="sequence">Sequence to cache.</param>
            public void Add(long position, ISequence sequence)
            {
                if (this.Count == 0)
                {
                    this.sequenceLength = (int)sequence.Count;
                }

                int index = (int)(position / (this.sequenceLength * this.bucketSize));
                SequenceHolder newHolder = new SequenceHolder() { Position = position, Sequence = sequence };

                if (index >= this.buckets.Count)
                {
                    while (index >= this.buckets.Count)
                    {
                        this.buckets.Add(null);
                    }

                    this.buckets[index] = newHolder;
                    this.Count++;
                    return;
                }

                SequenceHolder holder = this.buckets[index];
                if (holder == null)
                {
                    this.buckets[index] = newHolder;
                    this.Count++;
                    return;
                }

                if (holder.Position > position)
                {
                    this.buckets[index] = newHolder;
                    this.buckets[index].Next = holder;
                }
                else
                {
                    while (holder.Next != null)
                    {
                        if (holder.Next.Position > position)
                        {
                            break;
                        }

                        holder = holder.Next;
                    }

                    newHolder.Next = holder.Next;
                    holder.Next = newHolder;
                }

                this.Count++;
            }