Ejemplo n.º 1
0
        private void WriteText(Variant text)
        {
            switch (text.Type)
            {
            case VariantBase.EnumType.Any:
            case VariantBase.EnumType.String:
            {
                m_writer.WriteString(text.As <string>());
                break;
            }

            case VariantBase.EnumType.Int32:
            case VariantBase.EnumType.UInt32:
            case VariantBase.EnumType.Int64:
            case VariantBase.EnumType.UInt64:
            case VariantBase.EnumType.Float:
            case VariantBase.EnumType.Double:
            case VariantBase.EnumType.Boolean:
            case VariantBase.EnumType.Date:
            case VariantBase.EnumType.Time:
            case VariantBase.EnumType.DateTime:
            {
                m_writer.WriteString(text.AnyCast().As <string>());
                break;
            }

            default:
                throw new VariantException("Attempt to output non-primitive variant as text: " + text.Type);
            }
        }
Ejemplo n.º 2
0
        protected void WriteVariant(Variant v)
        {
            VariantBase.EnumType type = v.Type;
            Write((Int32)type);

            switch (type)
            {
            case VariantBase.EnumType.None:
                break;

            case VariantBase.EnumType.String:
            case VariantBase.EnumType.Any:
                Write(v.As <string>());
                break;

            case VariantBase.EnumType.Float:
                Write(v.As <float>());
                break;

            case VariantBase.EnumType.Double:
                Write(v.As <double>());
                break;

            case VariantBase.EnumType.Int32:
                Write(v.As <Int32>());
                break;

            case VariantBase.EnumType.UInt32:
                Write(v.As <UInt32>());
                break;

            case VariantBase.EnumType.Int64:
                Write(v.As <Int64>());
                break;

            case VariantBase.EnumType.UInt64:
                Write(v.As <UInt64>());
                break;

            case VariantBase.EnumType.Boolean:
                Write(v.As <bool>());
                break;

            case VariantBase.EnumType.Time:
                Write(v.As <TimeSpan>());
                break;

            case VariantBase.EnumType.DateTime:
                Write(v.As <DateTime>());
                break;

            case VariantBase.EnumType.List:
            case VariantBase.EnumType.Tuple:
                Write(v.Count);
                foreach (VariantItem item in v)
                {
                    WriteVariant(item.Value);
                }
                break;

            case VariantBase.EnumType.Dictionary:
            case VariantBase.EnumType.Bag:
                Write(v.Count);
                foreach (VariantItem item in v)
                {
                    Write(item.Key);
                    WriteVariant(item.Value);
                }
                break;

            case VariantBase.EnumType.TimeSeries:
                Write(v.Count);
                foreach (VariantItem item in v)
                {
                    Write(item.Time);
                    WriteVariant(item.Value);
                }
                break;

            case VariantBase.EnumType.Object:
                IVariantObject o = v.AsObject();
                Write(o.Class);
                Write(o.Version);
                WriteVariant(o.Deflate());
                break;

            case VariantBase.EnumType.Exception:
                VariantExceptionInfo x = v.AsException();
                Write(x.Class);
                Write(x.Message);
                Write(x.Source);
                Write(x.Stack);
                break;

            case VariantBase.EnumType.Buffer:
                Write(v.AsBuffer().Length);
                Write(v.AsBuffer(), true);
                break;

            case VariantBase.EnumType.DataTable:
                Write(v.AsDataTable());
                break;

            case VariantBase.EnumType.Array:
                Write(v.AsArray());
                break;

            default:
                throw new VariantException("Case exhaustion: " + type.ToString());
            }
        }
Ejemplo n.º 3
0
 private void WriteComment(Variant comment)
 {
     m_writer.WriteComment(comment.As <string>());
 }
Ejemplo n.º 4
0
        public static int GetByteCountVariant(Variant v)
        {
            VariantBase.EnumType type = v.Type;
            var writeCount            = sizeof(Int32);

            switch (type)
            {
            case VariantBase.EnumType.None:
                break;

            case VariantBase.EnumType.String:
            case VariantBase.EnumType.Any:
                writeCount += GetByteCountString(v.As <string>());
                break;

            case VariantBase.EnumType.Float:
                writeCount += sizeof(float);
                break;

            case VariantBase.EnumType.Double:
                writeCount += sizeof(double);
                break;

            case VariantBase.EnumType.Int32:
                writeCount += sizeof(Int32);
                break;

            case VariantBase.EnumType.UInt32:
                writeCount += sizeof(UInt32);
                break;

            case VariantBase.EnumType.Int64:
                writeCount += sizeof(Int64);
                break;

            case VariantBase.EnumType.UInt64:
                writeCount += sizeof(UInt64);
                break;

            case VariantBase.EnumType.Boolean:
                writeCount += sizeof(Int32);
                break;

            case VariantBase.EnumType.Time:
                writeCount += sizeof(Int64);
                break;

            case VariantBase.EnumType.DateTime:
                writeCount += sizeof(Int64);
                break;

            case VariantBase.EnumType.List:
            case VariantBase.EnumType.Tuple:
                writeCount += sizeof(Int32);
                foreach (VariantItem item in v)
                {
                    writeCount += GetByteCountVariant(item.Value);
                }
                break;

            case VariantBase.EnumType.Dictionary:
            case VariantBase.EnumType.Bag:
                writeCount += sizeof(Int32);
                foreach (VariantItem item in v)
                {
                    writeCount += GetByteCountString(item.Key);
                    writeCount += GetByteCountVariant(item.Value);
                }
                break;

            case VariantBase.EnumType.TimeSeries:
                writeCount += sizeof(Int32);
                foreach (VariantItem item in v)
                {
                    writeCount += sizeof(Int64);
                    writeCount += GetByteCountVariant(item.Value);
                }
                break;

            case VariantBase.EnumType.Object:
                IVariantObject o = v.AsObject();
                writeCount += GetByteCountString(o.Class);
                writeCount += sizeof(Int32);
                writeCount += GetByteCountVariant(o.Deflate());
                break;

            case VariantBase.EnumType.Exception:
                VariantExceptionInfo x = v.AsException();
                writeCount += GetByteCountString(x.Class);
                writeCount += GetByteCountString(x.Message);
                writeCount += GetByteCountString(x.Source);
                writeCount += GetByteCountString(x.Stack);
                break;

            case VariantBase.EnumType.Buffer:
                writeCount += sizeof(Int32);
                writeCount += GetByteCountBytes(v.AsBuffer().Length, true);
                break;

            case VariantBase.EnumType.DataTable:
                writeCount += GetByteCountDataTable(v.AsDataTable());
                break;

            case VariantBase.EnumType.Array:
                writeCount += GetByteCountArray(v.AsArray());
                break;

            default:
                throw new VariantException("Case exhaustion: " + type.ToString());
            }

            return(writeCount);
        }