public void AppendThenBuild(byte[][] byteArrays)
            {
                // Arrange
                var builder = new BinaryArray.Builder();

                foreach (var byteArray in byteArrays)
                {
                    // Test the type of byte array to ensure each Append() overload is exercised.
                    if (byteArray == null)
                    {
                        builder.AppendNull();
                    }
                    else if (byteArray.Length == 1)
                    {
                        builder.Append(byteArray[0]);
                    }
                    else
                    {
                        builder.Append((ReadOnlySpan <byte>)byteArray);
                    }
                }

                // Act
                var array = builder.Build(_allocator);

                // Assert
                AssertArrayContents(byteArrays, array);
            }
Esempio n. 2
0
        public void Encode(object row)
        {
            var val = _getFunc(row);

            if (_nullable && val == null)
            {
                _builder.AppendNull();
            }
            else
            {
                var byteArray = (byte[])val;
                size += byteArray.Length;
                _builder.Append(byteArray.AsSpan());
            }
        }
            public void Visit(BinaryType type)
            {
                BinaryArray.Builder resultBuilder = new BinaryArray.Builder().Reserve(_baseDataTotalElementCount);

                for (int i = 0; i < _baseDataListCount; i++)
                {
                    List <int?>         dataList = _baseData[i];
                    BinaryArray.Builder builder  = new BinaryArray.Builder().Reserve(dataList.Count);

                    foreach (byte?value in dataList)
                    {
                        if (value.HasValue)
                        {
                            builder.Append(value.Value);
                            resultBuilder.Append(value.Value);
                        }
                        else
                        {
                            builder.AppendNull();
                            resultBuilder.AppendNull();
                        }
                    }
                    TestTargetArrayList.Add(builder.Build());
                }

                ExpectedArray = resultBuilder.Build();
            }
            public void AppendSingleByteAfterClear(byte[][] initialContents, byte singleByte)
            {
                // Arrange
                var builder = new BinaryArray.Builder();

                if (initialContents.Length > 0)
                {
                    builder.AppendRange(initialContents);
                }
                builder.Clear();
                var expectedArrayContents = new[] { new[] { singleByte } };

                // Act
                var actualReturnValue = builder.Append(singleByte);

                // Assert
                Assert.Equal(builder, actualReturnValue);
                Assert.Equal(1, builder.Length);
                var actualArray = builder.Build(_allocator);

                AssertArrayContents(expectedArrayContents, actualArray);
            }
            public void AppendSingleByte(byte[][] initialContents, byte singleByte)
            {
                // Arrange
                var builder = new BinaryArray.Builder();

                if (initialContents.Length > 0)
                {
                    builder.AppendRange(initialContents);
                }
                int initialLength         = builder.Length;
                int expectedLength        = initialLength + 1;
                var expectedArrayContents = initialContents.Append(new[] { singleByte });

                // Act
                var actualReturnValue = builder.Append(singleByte);

                // Assert
                Assert.Equal(builder, actualReturnValue);
                Assert.Equal(expectedLength, builder.Length);
                var actualArray = builder.Build(_allocator);

                AssertArrayContents(expectedArrayContents, actualArray);
            }
            public void AppendEnumerableAfterClear(byte[][] initialContents, byte[] bytes)
            {
                // Arrange
                var builder = new BinaryArray.Builder();

                if (initialContents.Length > 0)
                {
                    builder.AppendRange(initialContents);
                }
                builder.Clear();
                var enumerable            = (IEnumerable <byte>)bytes;
                var expectedArrayContents = new[] { bytes };

                // Act
                var actualReturnValue = builder.Append(enumerable);

                // Assert
                Assert.Equal(builder, actualReturnValue);
                Assert.Equal(1, builder.Length);
                var actualArray = builder.Build(_allocator);

                AssertArrayContents(expectedArrayContents, actualArray);
            }
            public void AppendReadOnlySpan(byte[][] initialContents, byte[] bytes)
            {
                // Arrange
                var builder = new BinaryArray.Builder();

                if (initialContents.Length > 0)
                {
                    builder.AppendRange(initialContents);
                }
                int initialLength         = builder.Length;
                var span                  = (ReadOnlySpan <byte>)bytes;
                int expectedLength        = initialLength + 1;
                var expectedArrayContents = initialContents.Append(bytes);

                // Act
                var actualReturnValue = builder.Append(span);

                // Assert
                Assert.Equal(builder, actualReturnValue);
                Assert.Equal(expectedLength, builder.Length);
                var actualArray = builder.Build(_allocator);

                AssertArrayContents(expectedArrayContents, actualArray);
            }