示例#1
0
        public override bool TryWrite(ref ResizableMemory <byte> writer, T[] value, PropertyMap propMap = null)
        {
            if (value == null)
            {
                return(EtfWriter.TryWriteNull(ref writer));
            }

            var start = writer.Length;

            writer.Push((byte)EtfTokenType.List);
            writer.Advance(4);

            uint count = 0;

            for (int i = 0; i < value.Length; i++)
            {
                if (!_innerConverter.CanWrite(value[i], propMap))
                {
                    continue;
                }
                if (!_innerConverter.TryWrite(ref writer, value[i], propMap))
                {
                    return(false);
                }
                count++;
            }

            writer.Array[start + 1] = (byte)(count >> 24);
            writer.Array[start + 2] = (byte)(count >> 16);
            writer.Array[start + 3] = (byte)(count >> 8);
            writer.Array[start + 4] = (byte)count;

            writer.Push((byte)EtfTokenType.Nil); // Tail
            return(true);
        }
示例#2
0
 public override bool TryWrite(ref ResizableMemory <byte> writer, T?value, PropertyMap propMap = null)
 {
     if (value == null)
     {
         return(EtfWriter.TryWriteNull(ref writer));
     }
     return(_innerConverter.TryWrite(ref writer, value.Value, propMap));
 }
 public override bool TryWrite(ref ResizableMemory <byte> writer, Utf8String value, PropertyMap propMap = null)
 {
     if (value is null)
     {
         return(EtfWriter.TryWriteNull(ref writer));
     }
     else
     {
         return(EtfWriter.TryWrite(ref writer, value));
     }
 }
        public override bool TryWrite(ref ResizableMemory <byte> writer, T value, PropertyMap propMap = null)
        {
            if (value == null)
            {
                return(EtfWriter.TryWriteNull(ref writer));
            }

            var start = writer.Length;

            writer.Push((byte)EtfTokenType.Map);
            writer.Advance(4);

            uint count      = 0;
            var  properties = _map.Properties;

            for (int i = 0; i < properties.Count; i++)
            {
                var key          = properties[i].Key;
                var innerPropMap = properties[i].Value as PropertyMap <T>;
                if (!innerPropMap.CanWrite(value))
                {
                    continue;
                }

                if (!EtfWriter.TryWriteUtf8Key(ref writer, key.Span))
                {
                    return(false);
                }
                if (!innerPropMap.TryWrite(value, ref writer))
                {
                    return(false);
                }
                count++;
            }

            writer.Array[start + 1] = (byte)(count >> 24);
            writer.Array[start + 2] = (byte)(count >> 16);
            writer.Array[start + 3] = (byte)(count >> 8);
            writer.Array[start + 4] = (byte)count;
            return(true);
        }
示例#5
0
        public override bool TryWrite(ref ResizableMemory <byte> writer, Dictionary <string, T> value, PropertyMap propMap = null)
        {
            if (value == null)
            {
                return(EtfWriter.TryWriteNull(ref writer));
            }

            var start = writer.Length;

            writer.Push((byte)EtfTokenType.Map);
            writer.Advance(4);

            uint count = 0;

            foreach (var pair in value)
            {
                if (!_innerConverter.CanWrite(pair.Value, propMap))
                {
                    continue;
                }

                if (!EtfWriter.TryWriteUtf16Key(ref writer, pair.Key))
                {
                    return(false);
                }
                if (!_innerConverter.TryWrite(ref writer, pair.Value, propMap))
                {
                    return(false);
                }
                count++;
            }

            writer.Array[start + 1] = (byte)(count >> 24);
            writer.Array[start + 2] = (byte)(count >> 16);
            writer.Array[start + 3] = (byte)(count >> 8);
            writer.Array[start + 4] = (byte)count;
            return(true);
        }
 public override bool TryWrite(ref ResizableMemory <byte> writer, double value, PropertyMap propMap = null)
 => EtfWriter.TryWrite(ref writer, value, _format);