Exemplo n.º 1
0
        /// <summary>
        /// 根据字段的FieldId进行构建数据包
        /// </summary>
        /// <param name="fastmsg"></param>
        /// <param name="filedType"></param>
        /// <param name="filedValue"></param>
        /// <param name="filedIndex"></param>
        public static void SetFastMsgValueById(LDFastMessageAdapter fastmsg, int filedType, string filedValue, int fieldId)
        {
            switch (filedType)
            {
            case LDSdkTag.TypeInt16:
            case LDSdkTag.TypeuInt16:
            case LDSdkTag.TypeInt32:
            case LDSdkTag.TypeuInt32:
                Int32 intValue = 0;
                Int32.TryParse(filedValue, out intValue);
                //fastmsg.SetInt32byIndex(filedIndex, intValue);
                fastmsg.SetInt32(fieldId, intValue);
                break;

            case LDSdkTag.TypeInt64:
            case LDSdkTag.TypeuInt64:
                Int64 longValue = 0;
                Int64.TryParse(filedValue, out longValue);
                fastmsg.SetInt64(fieldId, (ulong)longValue);
                break;

            case LDSdkTag.TypeDouble:
                double doubleValue = 0;
                double.TryParse(filedValue, out doubleValue);
                fastmsg.SetDouble(fieldId, doubleValue);
                break;

            case LDSdkTag.TypeString:
            case LDSdkTag.TypeVector:
                if (string.IsNullOrEmpty(filedValue))
                {
                    filedValue = " ";
                }
                fastmsg.SetString(fieldId, filedValue);
                break;

            default:
                break;
            }
        }