Esempio n. 1
0
        private static byte[] DoSerialize(params BaseEntity[] entityList)
        {
            var rootWriter = new MessageStructure();
            rootWriter.PushIntoStack(entityList.Length);
            object fieldValue = null;
            foreach (var entity in entityList)
            {
                var schema = entity.GetSchema();
                if (schema == null)
                {
                    continue;
                }
                var recordWriter = new MessageStructure();
                recordWriter.PushIntoStack(schema.EntityName);
                //write columns
                var columns = schema.GetColumns();
                foreach (var column in columns)
                {
                    fieldValue = entity.GetPropertyValue(column.Name);
                    if (EntitySchemaSet.IsSupportType(column.ColumnType))
                    {
                        recordWriter.PushIntoStack(column.ColumnType, fieldValue);
                    }
                    else if (column.HasChild)
                    {
                        PushChildStack(recordWriter, column, fieldValue);
                    }
                }

                rootWriter.PushIntoStack(recordWriter);
            }

            var head = new MessageHead(SyncActionId);
            rootWriter.WriteBuffer(head);
            return rootWriter.PopBuffer();
        }
Esempio n. 2
0
        private static void PushChildStack(MessageStructure parent, SchemaColumn parentColumn, object value)
        {
            if (parentColumn.IsDictionary)
            {
                var column = parentColumn.Children[1];
                dynamic dict = value;
                dynamic keys = dict.Keys;
                int count = dict.Count;
                parent.PushIntoStack(count);
                foreach (var key in keys)
                {
                    object item = dict[key];
                    var itemWriter = new MessageStructure();
                    itemWriter.PushIntoStack(key);
                    if (EntitySchemaSet.IsSupportType(column.ColumnType))
                    {
                        itemWriter.PushIntoStack(column.ColumnType, item);
                    }
                    else if (column.HasChild)
                    {
                        PushChildStack(itemWriter, column, item);
                    }
                    parent.PushIntoStack(itemWriter);
                }
            }
            else if (parentColumn.IsList)
            {
                var column = parentColumn.Children[0];
                dynamic list = value;
                int count = list.Count;
                parent.PushIntoStack(count);
                foreach (var item in list)
                {
                    var itemWriter = new MessageStructure();
                    if (EntitySchemaSet.IsSupportType(column.ColumnType))
                    {
                        itemWriter.PushIntoStack(column.ColumnType, item);
                    }
                    else if (column.HasChild)
                    {
                        PushChildStack(itemWriter, column, item);
                    }
                    parent.PushIntoStack(itemWriter);
                }
            }
            else
            {
                //child entity object
                parent.PushIntoStack(1);
                var typeAccessor = ObjectAccessor.Create(value, true);
                var itemWriter = new MessageStructure();
                foreach (var column in parentColumn.Children)
                {
                    try
                    {
                        var fieldValue = typeAccessor[column.Name];
                        if (EntitySchemaSet.IsSupportType(column.ColumnType))
                        {
                            itemWriter.PushIntoStack(column.ColumnType, fieldValue);
                        }
                        else if (column.HasChild)
                        {
                            PushChildStack(itemWriter, column, fieldValue);
                        }
                    }
                    catch
                    {
                    }
                }
                parent.PushIntoStack(itemWriter);

            }
        }
Esempio n. 3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="response"></param>
 /// <param name="actionGetter"></param>
 /// <param name="errorCode"></param>
 /// <param name="errorInfo"></param>
 public virtual void ResponseError(BaseGameResponse response, ActionGetter actionGetter, int errorCode, string errorInfo)
 {
     string st = actionGetter.GetSt();
     ProtocolVersion prtcl = actionGetter.GetPtcl();
     MessageHead head = new MessageHead(actionGetter.GetMsgId(), actionGetter.GetActionId(), st, errorCode, errorInfo);
     MessageStructure sb = new MessageStructure();
     if (prtcl >= ProtocolVersion.ExtendHead)
     {
         sb.PushIntoStack(0); //不输出扩展头属性
     }
     sb.WriteBuffer(head);
     response.BinaryWrite(sb.PopBuffer());
 }