public void Can_ToUtf8_and_FromUtf8_using_Memory() { foreach (var test in Utf8Case.Source) { ReadOnlyMemory <byte> bytes = test.expectedString.AsMemory().ToUtf8(); Assert.That(bytes.Length, Is.EqualTo(test.count)); Assert.That(bytes.ToArray(), Is.EquivalentTo(test.expectedBytes)); ReadOnlyMemory <char> chars = bytes.FromUtf8(); Assert.That(chars.Length, Is.EqualTo(test.expectedString.Length)); Assert.That(chars.ToString(), Is.EqualTo(test.expectedString)); } }
public static bool IsStreamDeletedEvent( string streamOrMetaStreamId, string eventType, ReadOnlyMemory <byte> eventData, out string deletedPartitionStreamId) { bool isMetaStream; if (SystemStreams.IsMetastream(streamOrMetaStreamId)) { isMetaStream = true; deletedPartitionStreamId = streamOrMetaStreamId.Substring("$$".Length); } else { isMetaStream = false; deletedPartitionStreamId = streamOrMetaStreamId; } var isStreamDeletedEvent = false; if (isMetaStream) { if (eventType == SystemEventTypes.StreamMetadata) { var metadata = StreamMetadata.FromJson(eventData.FromUtf8()); //NOTE: we do not ignore JSON deserialization exceptions here assuming that metadata stream events must be deserializable if (metadata.TruncateBefore == EventNumber.DeletedStream) { isStreamDeletedEvent = true; } } } else { if (eventType == SystemEventTypes.StreamDeleted) { isStreamDeletedEvent = true; } } return(isStreamDeletedEvent); }