Interface in stdlib that returns []byte

blov · · 426 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>Hi, </p> <p>I am looking for a single method interface type in the stdlib with a method that just returns []byte. Any suggestions?</p> <hr/>**评论:**<br/><br/>DenzelM: <pre><p>What are you hoping to accomplish, exactly?</p></pre>metakeule: <pre><p>What are you hoping to accomplish with your question? :-D</p></pre>DenzelM: <pre><p>To understand your motivation, your intent. It&#39;s not exactly a question that I&#39;ve ever come across, or a need. Mainly because there&#39;s usually a reason for conforming to an interface, i.e., not simply blind conformance. And I&#39;m assuming, you have a reason... unless you don&#39;t. In other words, I&#39;m looking for the root cause of your question. Make sense?</p></pre>radovskyb: <pre><p>Running an inspection library I wrote in Go, I have found at least these examples. I&#39;m sure I could find more that return aliases for <code>[]byte</code> if I checked, but here&#39;s a few to name some.</p> <pre><code>Package: httputil Interface: BufferPool Method: func Get() []byte Package: http Interface: http2headersOrContinuation Method: func HeaderBlockFragment() []byte Package: macho Interface: Load Method: func Raw() []byte Package: cipher Interface: AEAD Method: func Seal(dst, nonce, plaintext, additionalData []byte) []byte Package: tls Interface: macFunction Method: func MAC(digestBuf, seq, header, data, extra []byte) []byte Package: tls Interface: constantTimeHash Method: func ConstantTimeSum(b []byte) []byte Package: tls Interface: handshakeMessage Method: func marshal() []byte Package: hash Interface: Hash Method: func Sum(b []byte) []byte </code></pre> <p>Edit: I&#39;ve now included the package names for you to have a look if you&#39;d like.</p> <p>Edit 2: I actually just realized you asked for a single method interface, so the above probably are incorrect for that question.</p> <p>Here are the single method ones from the above:</p> <pre><code>Package http: Interface: http2headersOrContinuation Method: func HeaderBlockFragment() []byte Package tls: Interface: constantTimeHash Method: func ConstantTimeSum(b []byte) []byte Package macho: Interface: Load Method: func Raw() []byte </code></pre> <p>Edit 3: The only single method interface out of the above that doesn&#39;t implement any other interfaces is the <code>Load</code> from the <code>macho</code> package one.</p></pre>DenzelM: <pre><p>That&#39;s pretty cool, is your tool open-source?</p></pre>radovskyb: <pre><p>Sure: <a href="https://github.com/radovskyb/inspect" rel="nofollow">https://github.com/radovskyb/inspect</a>.</p> <p>I just modified the example here to get the results: <a href="https://github.com/radovskyb/inspect/tree/master/example/extract_all_interfaces" rel="nofollow">https://github.com/radovskyb/inspect/tree/master/example/extract_all_interfaces</a>.</p> <p>Now if only I could remember how to format better on reddit xD</p> <p>Edit: The tool is quite simple at the moment and haven&#39;t really worked on it in a while, but I&#39;m sure I&#39;ll slowly add to it over time like I have been once in a great while :P</p></pre>DenzelM: <pre><p>That&#39;s sweet, thanks for sharing! It&#39;d be awesome to turn it into a cmdline tool that could construct queries that match patterns. Then we could run these type of queries as a one-liner; making <em>Inspect</em> a great compliment to <em>Go Guru</em>.</p> <p>I&#39;m not suggesting <em>you</em> do this, per se, since it would be a lot of work and I&#39;m sure you have your hands full. I&#39;m just thinking out loud.</p></pre>radovskyb: <pre><p>I&#39;m not the busiest person lately so that isn&#39;t much of a problem :P</p> <p>If I or someone else was going to turn it into a cmd line tool rather than just a library, I might consider first rewriting some of it to make it a bit better (it&#39;s not too bad at the moment I suppose), but then again, could be a fun idea :P</p></pre>metakeule: <pre><p>I hoped for a more general one like fmt.Stringer. debug/macho looks like a very specialized lib, seeing it for the first time.. ;-) But thanks anyway.</p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

426 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传