private static void _SerializePaths(FanoutSearchDescriptor search, TextWriter writer) { var paths = search.ToList().AsParallel().Select(p => { StringBuilder builder = new StringBuilder(); p.Serialize(builder); return(builder.ToString()); }); bool first = true; writer.Write('['); foreach (var path in paths) { if (first) { first = false; } else { writer.Write(','); } writer.Write(path); } writer.Write(']'); }
private static void _SerializePaths(FanoutSearchDescriptor search, TextWriter writer) { long len = 0; try { var paths = search.ToList().AsParallel().Select(p => { StringBuilder builder = new StringBuilder(); p.Serialize(builder); var newlen = Interlocked.Add(ref len, builder.Length); if (newlen > s_max_rsp_size) { throw new MessageTooLongException(); } return(builder.ToString()); }); bool first = true; writer.Write('['); foreach (var path in paths) { if (first) { first = false; } else { writer.Write(','); } writer.Write(path); } writer.Write(']'); } catch (AggregateException ex) when(ex.InnerExceptions.Any(_ => _ is MessageTooLongException || _ is OutOfMemoryException)) { throw new MessageTooLongException(); } catch (OutOfMemoryException) { throw new MessageTooLongException(); } }