コード例 #1
0
        public TarsStructBase DirectRead(TarsStructBase o, int tag, bool isRequire)
        {
            TarsStructBase reff = null;

            if (SkipToTag(tag))
            {
                try
                {
                    reff = o.NewInit();
                }
                catch (Exception e)
                {
                    throw new TarsDecodeException(e.Message);
                }
                var hd = new HeadData();
                ReadHead(hd);
                if (hd.Type != TarsStructBase.STRUCT_BEGIN)
                {
                    throw new TarsDecodeException("type mismatch.");
                }
                reff.ReadFrom(this);
                SkipToStructEnd();
            }
            else if (isRequire)
            {
                throw new TarsDecodeException("require field not exist.");
            }
            return(reff);
        }
コード例 #2
0
        public TarsStructBase ReadTarsStructBase(Type type, int tag, bool isRequire)
        {
            TarsStructBase reff = null;

            if (SkipToTag(tag))
            {
                try
                {
                    reff = (TarsStructBase)Activator.CreateInstance(type);
                }
                catch (Exception e)
                {
                    throw new TarsDecodeException(e.Message);
                }

                var hd = new HeadData();
                ReadHead(hd);
                if (hd.Type != TarsStructBase.STRUCT_BEGIN)
                {
                    throw new TarsDecodeException("type mismatch.");
                }
                reff.ReadFrom(this);
                SkipToStructEnd();
            }
            else if (isRequire)
            {
                throw new TarsDecodeException("require field not exist.");
            }
            return(reff);
        }
コード例 #3
0
        private TarsStructBase[] ReadTarsStructBaseArray(Type elementType, int tag, bool isRequire)
        {
            TarsStructBase[] lr = null;
            if (SkipToTag(tag))
            {
                var hd = new HeadData();
                ReadHead(hd);
                switch (hd.Type)
                {
                case TarsStructBase.LIST:
                {
                    int size = ReadInt(0, true);
                    if (size < 0)
                    {
                        throw new TarsDecodeException("size invalid: " + size);
                    }
                    lr = new TarsStructBase[size];
                    for (int i = 0; i < size; ++i)
                    {
                        lr[i] = ReadTarsStructBase(elementType, 0, true);
                    }
                    break;
                }

                default:
                    throw new TarsDecodeException("type mismatch.");
                }
            }
            else if (isRequire)
            {
                throw new TarsDecodeException("require field not exist.");
            }
            return(lr);
        }
コード例 #4
0
 public void Write(TarsStructBase o, int tag)
 {
     Reserve(2);
     WriteHead(TarsStructBase.STRUCT_BEGIN, tag);
     o.WriteTo(this);
     Reserve(2);
     WriteHead(TarsStructBase.STRUCT_END, 0);
 }