Exemple #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);
            }
        }
Exemple #2
0
        public override void Write(void *fieldAddress, SerializerOutput output)
        {
            var obj = Unsafe.Read <object>(fieldAddress);

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

            if (_stack >= MaxStack)
            {
                throw new CircularReferenceException("Circular references are not suported!");
            }

            _stack++;

            var track = output.BeginSizeTrack();

            var pinnable = Unsafe.As <object, PinnableObject>(ref obj);

            fixed(byte *objectAddress = &pinnable.Pinnable)
            {
                _fieldsSerializer.Write(objectAddress, output);
            }

            output.WriteSizeTrack(track);

            _stack--;
        }
Exemple #3
0
        public override void Write(void *fieldAddress, SerializerOutput output)
        {
            var track = output.BeginSizeTrack();

            _fieldsSerializer.Write((byte *)fieldAddress, output);

            output.WriteSizeTrack(track);
        }
        public override unsafe void Write(void *fieldAddress, SerializerOutput output)
        {
            if (Unsafe.Read <object>(fieldAddress) == null)
            {
                output.WriteNull();
                return;
            }

            var track = output.BeginSizeTrack();

            _memberSerializer.Write((byte *)fieldAddress, output);

            output.WriteSizeTrack(track);
        }
        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);
            }
        }