コード例 #1
0
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            var list = (ICompressedList)value;

            if (list == null)
            {
                writer.WriteNull();
                return;
            }

            if (list.Count <= list.MaxUncompressedCount)
            {
                list.WriteRaw(writer, serializer);
                return;
            }

            string raw;

            using (var tempWriter = GetTempWriter())
            {
                list.WriteRaw(tempWriter.Writer, serializer);
                raw = tempWriter.GetString();
            }

            writer.WriteValue(LZString.compressToBase64(raw));
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: yigitnerukuc/SourceUtils
        public static string CompressArray <T>(IEnumerable <T> enumerable, Func <T, string> serializer)
        {
            if (_sArrayBuilder == null)
            {
                _sArrayBuilder = new StringBuilder();
            }
            else
            {
                _sArrayBuilder.Remove(0, _sArrayBuilder.Length);
            }

            _sArrayBuilder.Append("[");
            foreach (var item in enumerable)
            {
                _sArrayBuilder.Append(serializer(item));
                _sArrayBuilder.Append(",");
            }

            if (_sArrayBuilder.Length > 1)
            {
                _sArrayBuilder.Remove(_sArrayBuilder.Length - 1, 1);
            }
            _sArrayBuilder.Append("]");

            return(LZString.compressToBase64(_sArrayBuilder.ToString()));
        }