示例#1
0
    private void WriteCell(ByteBuffer buffer, HeadWrapper head, string value, string createLogo)
    {
        if (head.IsNotes || head.Logo.Contains(createLogo) == false)
        {
            return;
        }

        if (head.Type == "int")
        {
            buffer.WriteInt(StringConvert.StringToValue <int>(value));
        }
        else if (head.Type == "long")
        {
            buffer.WriteLong(StringConvert.StringToValue <long>(value));
        }
        else if (head.Type == "float")
        {
            buffer.WriteFloat(StringConvert.StringToValue <float>(value));
        }
        else if (head.Type == "double")
        {
            buffer.WriteDouble(StringConvert.StringToValue <double>(value));
        }

        else if (head.Type == "List<int>")
        {
            buffer.WriteListInt(StringConvert.StringToValueList <int>(value, ConstDefine.StrSplitChar));
        }
        else if (head.Type == "List<long>")
        {
            buffer.WriteListLong(StringConvert.StringToValueList <long>(value, ConstDefine.StrSplitChar));
        }
        else if (head.Type == "List<float>")
        {
            buffer.WriteListFloat(StringConvert.StringToValueList <float>(value, ConstDefine.StrSplitChar));
        }
        else if (head.Type == "List<double>")
        {
            buffer.WriteListDouble(StringConvert.StringToValueList <double>(value, ConstDefine.StrSplitChar));
        }

        // bool
        else if (head.Type == "bool")
        {
            buffer.WriteBool(StringConvert.StringToBool(value));
        }

        // string
        else if (head.Type == "string")
        {
            buffer.WriteUTF(value);
        }
        else if (head.Type == "List<string>")
        {
            buffer.WriteListUTF(StringConvert.StringToStringList(value, ConstDefine.StrSplitChar));
        }

        // NOTE:多语言在字节流会是哈希值
        else if (head.Type == "language")
        {
            buffer.WriteInt(value.GetHashCode());
        }
        else if (head.Type == "List<language>")
        {
            List <string> langList = StringConvert.StringToStringList(value, ConstDefine.StrSplitChar);
            List <int>    hashList = new List <int>();
            for (int i = 0; i < langList.Count; i++)
            {
                hashList.Add(langList[i].GetHashCode());
            }
            buffer.WriteListInt(hashList);
        }

        // wrapper
        else if (head.Type.Contains("class"))
        {
            buffer.WriteUTF(value);
        }

        // enum
        else if (head.Type.Contains("enum"))
        {
            buffer.WriteInt(StringConvert.StringToValue <int>(value));
        }

        else
        {
            throw new Exception($"Not support head type {head.Type}");
        }
    }