Пример #1
0
        public override unsafe void Write(void *fieldAddress, SerializerOutput output)
        {
            var array = Unsafe.Read <bool[]>(fieldAddress);

            if (array == null)
            {
                output.WriteNull();
                return;
            }

            var count = array.Length;

            if (count > 0)
            {
                var sizeTracker = output.BeginSizeTrack();
                {
                    output.EnsureNext(6 + (count * sizeof(bool)));
                    output.Write7BitEncodedIntUnchecked(count);
                    output.WriteByteUnchecked((byte)_elementDataType);
                    output.WriteBoolsUnchecked(array, count);
                }
                output.WriteSizeTrack(sizeTracker);
            }
            else
            {
                output.EnsureNext(5);
                output.WriteIntUnchecked(1); //size tracker
                output.WriteByteUnchecked(0);
            }
        }
Пример #2
0
        public override void Write(void *fieldAddress, SerializerOutput output)
        {
            var array = Unsafe.Read <Array>(fieldAddress);

            if (array == null)
            {
                output.WriteNull();
                return;
            }

            var count = array.Length;


            if (count > 0)
            {
                var sizeTracker = output.BeginSizeTrack();
                {
                    output.EnsureNext(6);
                    output.Write7BitEncodedIntUnchecked(count);
                    output.WriteByteUnchecked((byte)_elementDataType);

                    var pinnable = Unsafe.As <Array, byte[]>(ref array);

                    fixed(byte *address = pinnable)
                    {
                        var tempAddress = address;

                        for (var index = 0; index < count; index++)
                        {
                            _elementSerializer.Write(tempAddress, output);
                            tempAddress += _size;
                        }
                    }
                }
                output.WriteSizeTrack(sizeTracker);
            }
            else
            {
                output.EnsureNext(5);
                output.WriteIntUnchecked(1); //size tracker
                output.WriteByteUnchecked(0);
            }
        }