public void Write(object obj, FormatWriter writer)
        {
            DateTime value = (DateTime)obj;

            switch (context.DateTimeOptions.PackingFormat)
            {
            case DateTimePackingFormat.Extension:
                TimeSpan diff = value.ToUniversalTime() - epoch;
                writer.WriteExtHeader(12, ExtType);
                writer.WriteUInt32((uint)(value.Ticks % 10000000) * 100);
                writer.WriteUInt64((ulong)diff.TotalSeconds);
                break;

            case DateTimePackingFormat.String:
                writer.Write(value.ToString("o"));
                break;

            case DateTimePackingFormat.Epoch:
                writer.Write((value.ToUniversalTime() - epoch).TotalSeconds);
                break;

            default:
                throw new FormatException();
            }
        }
        public void Write(object obj, FormatWriter writer)
        {
            Vector2 vector = (Vector2)obj;

            writer.WriteArrayHeader(2);
            writer.Write(vector.x);
            writer.Write(vector.y);
        }
示例#3
0
 public void Write(object obj, FormatWriter writer)
 {
     if (obj == null)
     {
         writer.WriteNil();
         return;
     }
     context.TypeHandlers.Get(obj.GetType()).Write(obj, writer);
 }
 public void Write(object obj, FormatWriter writer)
 {
     if (obj == null)
     {
         writer.WriteNil();
         return;
     }
     underlyingTypeHandler.Write(obj, writer);
 }
示例#5
0
        public void Write(object obj, FormatWriter writer)
        {
            Color color = (Color)obj;

            writer.WriteArrayHeader(4);
            writer.Write(color.r);
            writer.Write(color.g);
            writer.Write(color.b);
            writer.Write(color.a);
        }
示例#6
0
        public void Write(object obj, FormatWriter writer)
        {
            Vector4 vector = (Vector4)obj;

            writer.WriteArrayHeader(4);
            writer.Write(vector.x);
            writer.Write(vector.y);
            writer.Write(vector.z);
            writer.Write(vector.w);
        }
        public void Write(object obj, FormatWriter writer)
        {
            Quaternion quaternion = (Quaternion)obj;

            writer.WriteArrayHeader(4);
            writer.Write(quaternion.x);
            writer.Write(quaternion.y);
            writer.Write(quaternion.z);
            writer.Write(quaternion.w);
        }
示例#8
0
        public void Write(object obj, FormatWriter writer)
        {
            Color32 color = (Color32)obj;

            writer.WriteBinHeader(4);
            writer.WriteRawByte(color.r);
            writer.WriteRawByte(color.g);
            writer.WriteRawByte(color.b);
            writer.WriteRawByte(color.a);
        }
示例#9
0
        public void Write(object obj, FormatWriter writer)
        {
            if (obj == null)
            {
                writer.WriteNil();
                return;
            }
            string value = ((Uri)obj).ToString();

            GetStringHandler().Write(value, writer);
        }
示例#10
0
        public void Write(object obj, FormatWriter writer)
        {
            if (obj == null)
            {
                writer.WriteNil();
                return;
            }
            Array values = (Array)obj;

            writer.WriteArrayHeader(values.Length);
            foreach (object value in values)
            {
                elementTypeHandler.Write(value, writer);
            }
        }
        public void Write(object obj, FormatWriter writer)
        {
            switch (context.EnumOptions.PackingFormat)
            {
            case EnumPackingFormat.Integer:
                intHandler = intHandler ?? context.TypeHandlers.Get <int>();
                intHandler.Write(obj, writer);
                break;

            case EnumPackingFormat.String:
                stringHandler = stringHandler ?? context.TypeHandlers.Get <string>();
                stringHandler.Write(obj.ToString(), writer);
                break;
            }
        }
示例#12
0
        public void Write(object obj, FormatWriter writer)
        {
            if (obj == null)
            {
                writer.WriteNil();
                return;
            }
            IList values = (IList)obj;

            writer.WriteArrayHeader(values.Count);
            foreach (object value in values)
            {
                innerTypeHandler.Write(value, writer);
            }
        }
示例#13
0
        public void Write(object obj, FormatWriter writer)
        {
            if (obj == null)
            {
                writer.WriteNil();
                return;
            }
            IDictionary dictionary = (IDictionary)obj;

            writer.WriteMapHeader(dictionary.Count);
            foreach (DictionaryEntry kv in dictionary)
            {
                keyHandler.Write(kv.Key, writer);
                valueHandler.Write(kv.Value, writer);
            }
        }
        public void Write(object obj, FormatWriter writer)
        {
            if (obj == null)
            {
                writer.WriteNil();
                return;
            }
            MapDefinition definition = lazyDefinition.Value;

            InvokeCallback <OnSerializingAttribute>(obj, definition);
            writer.WriteMapHeader(DetermineSize(obj, definition));
            foreach (KeyValuePair <string, FieldInfo> kv in definition.FieldInfos)
            {
                object value = kv.Value.GetValue(obj);
                if (context.MapOptions.IgnoreNullOnPack && value == null)
                {
                    continue;
                }
                string name = nameConverter.OnPack(kv.Key, definition);
                nameHandler.Write(name, writer);
                definition.FieldHandlers[kv.Key].Write(value, writer);
            }
            InvokeCallback <OnSerializedAttribute>(obj, definition);
        }
示例#15
0
 public void Write(object obj, FormatWriter writer)
 {
     writer.Write((string)obj);
 }
示例#16
0
 public void Write(object obj, FormatWriter writer)
 {
     writer.Write(Convert.ToUInt32(obj));
 }
示例#17
0
 public void Write(object obj, FormatWriter writer)
 {
     writer.Write(((TimeSpan)obj).Ticks);
 }
示例#18
0
 public void Write(object obj, FormatWriter writer)
 {
     writer.Write((float)obj);
 }
示例#19
0
 public void Write(object obj, FormatWriter writer)
 {
     intArrayHandler = intArrayHandler ?? context.TypeHandlers.Get <int[]>();
     int[] bits = decimal.GetBits((decimal)obj);
     intArrayHandler.Write(bits, writer);
 }
示例#20
0
 public void Write(object obj, FormatWriter writer)
 {
     binaryHandler = binaryHandler ?? context.TypeHandlers.Get <byte[]>();
     binaryHandler.Write(((Guid)obj).ToByteArray(), writer);
 }
示例#21
0
 public void Write(object obj, FormatWriter writer)
 {
     writer.Write((bool)obj);
 }
示例#22
0
 public void Write(object obj, FormatWriter writer)
 {
     writer.Write((double)obj);
 }