<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">The reason why `ManagedProtoBuffer` (the base class of `ManagedBuffer`) exists is to give the users an extra bit of type safety inside of the closure `initialHeader` passed to `ManagedBuffer.create()`.<div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class="">public class ManagedBuffer<Header, Element></font></div><div class=""><font face="Menlo" class=""> : ManagedProtoBuffer<Header, Element> {</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""> /// Create a new instance of the most-derived class, calling</font></div><div class=""><font face="Menlo" class=""> /// `initialHeader` on the partially-constructed object to</font></div><div class=""><font face="Menlo" class=""> /// generate an initial `Header`.</font></div><div class=""><font face="Menlo" class=""> public final class func create(</font></div><div class=""><font face="Menlo" class=""> minimumCapacity: Int,</font></div><div class=""><font face="Menlo" class=""> initialHeader: @noescape (ManagedProtoBuffer<Header, Element>) throws -> Header</font></div><div class=""><font face="Menlo" class=""> ) rethrows -> ManagedBuffer<Header, Element> {</font></div><div class=""><font face="Menlo" class=""> // ...</font></div><div class=""><font face="Menlo" class=""> }</font></div></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><br class=""></div><div class="">This closure receives the `ManagedBuffer` instance and returns the initial value that is stored in the buffer (the header part of the buffer). We are passing the `ManagedBuffer` as `ManagedProtoBuffer` to prevent the closure from reading the uninitialized `value` property. This property is defined in `ManagedBuffer` but not in `ManagedProtoBuffer`.</div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class=""> public final var header: Header {</font></div><div class=""><font face="Menlo" class=""> // ...</font></div></div><div class=""><font face="Menlo" class=""> }</font></div><div class=""><br class=""></div><div class="">This extra bit of safety requires the existence of `ManagedProtoBuffer`, which complicates the API.</div><div class="">The name may also lead to some confusion with Google's Protocol Buffers project.</div><div class=""><br class=""></div><div class="">This proposal suggests removing `ManagedProtoBuffer` in order to simplify the API.</div><div class="">It means that `ManagedBuffer` would not be derived from `ManagedProtoBuffer` and all methods from `ManagedProtoBuffer` would be moved to `ManagedBuffer`.</div><div class="">The closure `initialHeader` would receive a `ManagedBuffer` instead of a `ManagedProtoBuffer`.</div><div class=""><br class=""></div><div class=""><div class=""><div class=""><font face="Menlo" class="">public class ManagedBuffer<Header, Element></font><span style="font-family: Menlo;" class=""> {</span></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class=""> /// Create a new instance of the most-derived class, calling</font></div><div class=""><font face="Menlo" class=""> /// `initialHeader` on the partially-constructed object to</font></div><div class=""><font face="Menlo" class=""> /// generate an initial `Header`.</font></div><div class=""><font face="Menlo" class=""> public final class func create(</font></div><div class=""><font face="Menlo" class=""> minimumCapacity: Int,</font></div><div class=""><font face="Menlo" class=""> initialHeader: @noescape (ManagedBuffer<Header, Element>) throws -> Header</font></div><div class=""><font face="Menlo" class=""> ) rethrows -> ManagedBuffer<Header, Element> {</font></div><div class=""><font face="Menlo" class=""> // ...</font></div><div class=""><font face="Menlo" class=""> }</font></div></div><div class=""><font face="Menlo" class="">}</font></div><div class=""><br class=""></div></div><div class=""><div class="">Also `ManagedBufferPointer`'s init function (the second occurrence of `ManagedProtoBuffer`) would receive a `ManagedBuffer` instead of a `ManagedProtoBuffer`:</div></div><div class=""><br class=""></div><div class=""><div class=""><font face="Menlo" class=""> /// Manage the given `buffer`.</font></div><div class=""><font face="Menlo" class=""> ///</font></div><div class=""><font face="Menlo" class=""> /// - Note: It is an error to use the `header` property of the resulting</font></div><div class=""><font face="Menlo" class=""> /// instance unless it has been initialized.</font></div><div class=""><font face="Menlo" class=""> internal init(_ buffer: ManagedBuffer<Header, Element>) {</font></div><div class=""><font face="Menlo" class=""> _nativeBuffer = Builtin.castToNativeObject(buffer)</font></div><div class=""><font face="Menlo" class=""> }</font></div><div class=""><br class=""></div></div><div class=""><br class=""></div><div class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">Motivation
==========</pre></div><div class="">The removal of `ManagedProtoBuffer` would simplify the API and avoids confusion with Google's Protocol Buffers.</div><div class=""><br class=""></div><div class=""><pre style="white-space: pre-wrap; background-color: rgb(255, 255, 255);" class="">Alternatives
============</pre></div><div class="">*) Leave as is.</div><div class="">*) Rename the class to avoid the "confusion"-problem.</div><div class=""><br class=""></div></body></html>