| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System.Collections.Generic; |
| | | 5 | | using System.Threading; |
| | | 6 | | using System.Threading.Tasks; |
| | | 7 | | using Azure.Storage.Internal.Avro; |
| | | 8 | | |
| | | 9 | | namespace Azure.Storage.Blobs.ChangeFeed |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Chunk. |
| | | 13 | | /// </summary> |
| | | 14 | | internal class Chunk |
| | | 15 | | { |
| | | 16 | | /// <summary> |
| | | 17 | | /// Avro Reader to parser the Events. |
| | | 18 | | /// </summary> |
| | | 19 | | private readonly AvroReader _avroReader; |
| | | 20 | | |
| | | 21 | | /// <summary> |
| | | 22 | | /// The byte offset of the beginning of the current |
| | | 23 | | /// Block. |
| | | 24 | | /// </summary> |
| | 30204 | 25 | | public virtual long BlockOffset { get; private set; } |
| | | 26 | | |
| | | 27 | | /// <summary> |
| | | 28 | | /// The index of the Event within the current block. |
| | | 29 | | /// </summary> |
| | 30204 | 30 | | public virtual long EventIndex { get; private set; } |
| | | 31 | | |
| | | 32 | | /// <summary> |
| | | 33 | | /// The path of the chunk. |
| | | 34 | | /// </summary> |
| | 620 | 35 | | public virtual string ChunkPath { get; private set; } |
| | | 36 | | |
| | 228 | 37 | | public Chunk( |
| | 228 | 38 | | AvroReader avroReader, |
| | 228 | 39 | | long blockOffset, |
| | 228 | 40 | | long eventIndex, |
| | 228 | 41 | | string chunkPath) |
| | | 42 | | { |
| | 228 | 43 | | _avroReader = avroReader; |
| | 228 | 44 | | BlockOffset = blockOffset; |
| | 228 | 45 | | EventIndex = eventIndex; |
| | 228 | 46 | | ChunkPath = chunkPath; |
| | 228 | 47 | | } |
| | | 48 | | |
| | | 49 | | public virtual bool HasNext() |
| | 118548 | 50 | | => _avroReader.HasNext(); |
| | | 51 | | |
| | | 52 | | public virtual async Task<BlobChangeFeedEvent> Next( |
| | | 53 | | bool async, |
| | | 54 | | CancellationToken cancellationToken = default) |
| | | 55 | | { |
| | | 56 | | Dictionary<string, object> result; |
| | | 57 | | |
| | 29584 | 58 | | if (!HasNext()) |
| | | 59 | | { |
| | 0 | 60 | | return null; |
| | | 61 | | } |
| | | 62 | | |
| | 29584 | 63 | | result = (Dictionary<string, object>)await _avroReader.Next(async, cancellationToken).ConfigureAwait(false); |
| | 29584 | 64 | | BlockOffset = _avroReader.BlockOffset; |
| | 29584 | 65 | | EventIndex = _avroReader.ObjectIndex; |
| | 29584 | 66 | | return new BlobChangeFeedEvent(result); |
| | 29584 | 67 | | } |
| | | 68 | | |
| | | 69 | | /// <summary> |
| | | 70 | | /// Constructor for mocking. Do not use. |
| | | 71 | | /// </summary> |
| | 64 | 72 | | internal Chunk() { } |
| | | 73 | | } |
| | | 74 | | } |