<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="">The disadvantage of Collection over Array (or UnsafePointer) is that there is not standardised way to quickly get a raw pointer to it, right? How would you efficiently grab the data, by iterating over the Collection? :-)<br class=""><br class="">Also, what you propose doesn’t actually work in Swift 3.0. Does it work in 3.1 or 4? (`error: cannot specialize non-generic type ‘Collection’`)<br class=""><br class=""><blockquote type="cite" class="">Like the followings:<br class="">func tlsWrite(buffer: Collection<UInt8>) throws<br class="">func tlsWritev(vectors: Collection<iovec>)<br class=""><br class="">If it is possible it will be very helpful since <br class="">1) it is very swifty and user friendly<br class="">2) vectorIO could significantly reduce the overhead to merge fragments of bytes into a single buffer.<br class=""></blockquote><br class="">+1 on vectors.<br class=""><br class="">My headache with the design is that it doesn’t support async I/O (even if you don’t implement that right away, you could still design the API to support it). For read/write I would propose to match the GCD channel API.<br class=""><br class="">hh<br class=""><br class=""></div></div></blockquote><div class=""><br class=""></div>Collection will never work since it is a generic protocol. But Collection<UInt8> will work. </div><div class="">I’m not quite sure if there’s way to write bytes into OpenSSL’s BIO, I guess it’s probably not, but if it’s possible we should be able to write bytes into the buffer directly.</div><div class="">An other alternative solution is to add an other layer of protocol, to force the type the collection contains must provide a method for raw byte access to the object it contains.</div><div class=""><br class=""></div><div class="">For example let’s say:</div><div class=""><br class=""></div><div class="">protocol RawBufferRepresentable {</div><div class=""> func rawBuffer() -> (UnsafeRawPointer, Int)</div><div class="">}</div><div class=""><br class=""></div><div class="">And on the TLS side:</div><div class="">fun tlsWrite(contents: AnyCollection<RawBufferRepresentable>)</div><div class=""><br class=""></div><div class="">Or even</div><div class=""><br class=""></div><div class=""><div class="">protocol IOVectorRepresentable {</div><div class=""> func vectors() -> [iovec]</div><div class="">}</div><div class=""><br class=""></div><div class="">fun tlsWritev(vector: IOVectorRepresentable)</div><div class=""><br class=""></div></div>For vector IO, actually I started a project on DiscreteData type, which could theoretically archive zero copy (even on some writes) and reducing duplicated contents in the same buffer. The project is in very early stage but some fundamental feature is already working. Please check it out if interested. There should be still a lot of bugs, tho.<div class=""><br class=""><div class=""><a href="https://github.com/michael-yuji/DiscreteData" class="">https://github.com/michael-yuji/DiscreteData</a></div><div class=""><br class=""></div><div class="">Michael</div></div></div></body></html>