Exemple #1
0
        public void ExtractBytesHasTheSameBuffer()
        {
            byte[] input      = new byte[] { 1, 2, 3 };
            var    byteString = ByteStringExtensions.UnsafeCreateFromBytes(input);
            var    buffer     = ByteStringExtensions.UnsafeExtractBytes(byteString);

            Assert.True(ReferenceEquals(buffer, input));
        }
Exemple #2
0
        public void UnsafeCreateFromBytesCreatesTheInstance()
        {
            byte[] input      = new byte[] { 1, 2, 3 };
            var    byteString = ByteStringExtensions.UnsafeCreateFromBytes(input);

            var byteString2 = ByteString.CopyFrom(input);

            // ByteString uses "value" comparison. So two "strings" are equals even
            // when they point to different byte arrays.
            // This test mostely checks that the hacky solution works.
            Assert.Equal(byteString, byteString2);
        }