Esempio n. 1
0
 public void Write(ApolloBufferBase ab)
 {
     if (ab != null)
     {
         ab.Encode(this);
     }
 }
Esempio n. 2
0
 public ApolloBufferBase Read(ref ApolloBufferBase ab)
 {
     if (ab != null)
     {
         ab.Decode(this);
     }
     return(ab);
 }
Esempio n. 3
0
        public T Read <T>(string name) where T : ApolloBufferBase
        {
            ApolloBufferBase target = Activator.CreateInstance <T>();

            if (!Read(name, ref target))
            {
                return(null);
            }
            return(target as T);
        }
Esempio n. 4
0
        public bool Read(string name, ref ApolloBufferBase target)
        {
            int len = abase_apollo_object_get_len(this.ObjectId, name);

            if (len > 0)
            {
                byte[] buffer = new byte[len];
                if (abase_apollo_object_read_buffer(this.ObjectId, name, buffer, len))
                {
                    return(target.Decode(buffer));
                }
            }
            return(false);
        }
Esempio n. 5
0
        public object Read <T>(ref T o)
        {
            if (o == null)
            {
                o = (T)BasicClassTypeUtil.CreateObject <T>();
            }

            if (o is Byte || o is Char)
            {
                byte b = 0;

                o = (T)(object)(Read(ref b));
            }
            else if (o is char)
            {
                byte c = 0;
                o = (T)(object)(Read(ref c));
            }
            else if (o is Boolean)
            {
                bool b = false;
                o = (T)(object)(Read(ref b));
            }
            else if (o is short)
            {
                short s = 0;
                o = (T)(object)(Read(ref s));
            }
            else if (o is ushort)
            {
                ushort us = 0;
                o = (T)(object)(Read(ref us));
            }
            else if (o is int)
            {
                int i = 0;
                o = (T)(object)Read(ref i);
            }
            else if (o is uint)
            {
                uint ui = 0;
                o = (T)(object)Read(ref ui);
                return(o);
            }
            else if (o is long)
            {
                long l = 0;
                o = (T)(object)Read(ref l);
                return(o);
            }
            else if (o is Enum)
            {
                int remp = 0;
                o = (T)(object)Read(ref remp);
                return(o);
            }
            else if (o is ulong)
            {
                ulong  ul = 0;
                object oo = (Read(ref ul));
                o = (T)oo;
                return(oo);
            }/*
              * else if (o is float)
              * {
              * return (Read());
              * }
              * else if (o is Double)
              * {
              * return (Read());
              * }*/
            else if (o is string)
            {
                string s = "";
                o = (T)(object)Read(ref s);
            }
            else if (o is ApolloBufferBase)
            {
                ApolloBufferBase oo = o as ApolloBufferBase;
                o = (T)(object)Read(ref oo);
            }
            else if (o != null && o.GetType().IsArray)
            {
                /*
                 * if (o is byte[] || o is Byte[])
                 * {
                 *  return Read((byte[])null);
                 * }
                 * else if (o is bool[])
                 * {
                 *  return Read((bool[])null);
                 * }
                 * else if (o is short[])
                 * {
                 *  return Read((short[])null);
                 * }
                 * else if (o is int[])
                 * {
                 *  return Read((int[])null);
                 * }
                 * else if (o is long[])
                 * {
                 *  return Read((long[])null);
                 * }
                 * else if (o is float[])
                 * {
                 *  return Read((float[])null);
                 * }
                 * else if (o is double[])
                 * {
                 *  return Read((double[])null);
                 * }
                 * else
                 * {
                 *  object oo = o;
                 *  return readArray((Object[])oo);
                 * }
                 */
            }
            else if (o is IList)
            {
                return(ReadList <T>(ref o));
            }
            else if (o is IDictionary)
            {
                return(ReadMap <T>(ref o));
            }
            else
            {
                throw new Exception("read object error: unsupport type:" + o.GetType() + " value:" + o.ToString());
            }

            return(o);
        }