示例#1
0
        public static BaseData bytetoBaseData(Proto.BaseData proBD)
        {
            BaseData bsData = null;

            if (proBD.MIsBaseObject != true)
            {
                if (proBD.MValue == null)
                {
                    bsData = new BaseData(null);
                }
                else if (proBD.MValue.MType == 0)
                {
                    bsData = new BaseData(null);
                }
                else if (proBD.MValue.MType == 1)
                {
                    bsData = new BaseData(proBD.MValue.BvInt);
                }
                else if (proBD.MValue.MType == 2)
                {
                    bsData = new BaseData(proBD.MValue.BvFloat);
                }
                else if (proBD.MValue.MType == 3)
                {
                    bsData = new BaseData(proBD.MValue.BvDouble);
                }
                else if (proBD.MValue.MType == 4)
                {
                    bsData = new BaseData(proBD.MValue.BvString);
                }
                else if (proBD.MValue.MType == 5)
                {
                    bsData = new BaseData(proBD.MValue.BvBool);
                }
                else if (proBD.MValue.MType == 6)
                {
                    bsData = new BaseData(proBD.MValue.BvLong);
                }
            }
            else
            {
                bsData = new BaseData(null);
                bsData.createObject();
                int objSize = proBD.MObject.Count;
                for (int i = 0; i < objSize; i++)
                {
                    Proto.BaseData.Types.ObjectType keyValue = proBD.MObject[i];
                    if (keyValue.MKey.MType == 1)
                    {
                        bsData.putObject(keyValue.MKey.BvInt, bytetoBaseData(keyValue.MValue));
                    }
                    else if (keyValue.MKey.MType == 4)
                    {
                        bsData.putObject(keyValue.MKey.BvString, bytetoBaseData(keyValue.MValue));
                    }
                }
            }
            return(bsData);
        }
示例#2
0
        public Proto.BaseData toProtoBuf()
        {
            Proto.BaseData bsData = new Proto.BaseData {
            };
            if (mIsBaseObject == false)
            {
                bsData.MIsBaseObject = false;

                if (mValue == null)
                {
                    bsData.MValue = new Proto.BaseData.Types.BaseValue {
                        MType = 0
                    };
                    return(bsData);
                }
                else
                {
                    if (mValue is int)
                    {
                        bsData.MValue = new Proto.BaseData.Types.BaseValue {
                            BvInt = (int)mValue, MType = 1
                        };
                    }
                    else if (mValue is float)
                    {
                        bsData.MValue = new Proto.BaseData.Types.BaseValue {
                            BvFloat = (float)mValue, MType = 2
                        };
                    }
                    else if (mValue is double)
                    {
                        bsData.MValue = new Proto.BaseData.Types.BaseValue {
                            BvDouble = (double)mValue, MType = 3
                        };
                    }
                    else if (mValue is String)
                    {
                        bsData.MValue = new Proto.BaseData.Types.BaseValue {
                            BvString = (String)mValue, MType = 4
                        };
                    }
                    else if (mValue is bool)
                    {
                        bsData.MValue = new Proto.BaseData.Types.BaseValue {
                            BvBool = (bool)mValue, MType = 5
                        };
                    }
                    else if (mValue is long)
                    {
                        bsData.MValue = new Proto.BaseData.Types.BaseValue {
                            BvLong = (long)mValue, MType = 6
                        };
                    }
                    else if (mValue is short)
                    {
                        bsData.MValue = new Proto.BaseData.Types.BaseValue {
                            BvInt = (int)mValue, MType = 1
                        };
                    }
                    return(bsData);
                }
            }
            else
            {
                bsData.MIsBaseObject = true;
                foreach (var item in mObject)
                {
                    BaseData value = item.Value;
                    Object   key   = item.Key;
                    Proto.BaseData.Types.BaseValue keyData = new Proto.BaseData.Types.BaseValue {
                    };
                    if (key is String)
                    {
                        keyData.BvString = ((String)key);
                        keyData.MType    = 4;
                    }
                    else if (key is int)
                    {
                        keyData.BvInt = ((int)key);
                        keyData.MType = 1;
                    }
                    else
                    {
                        continue;
                    }
                    Proto.BaseData.Types.ObjectType objData = new Proto.BaseData.Types.ObjectType {
                    };
                    objData.MKey   = keyData;
                    objData.MValue = value.toProtoBuf();
                    bsData.MObject.Add(objData);
                }
            }
            return(bsData);
        }