2016-12-20 22:13
浏览 473


I am working on SIP over TCP mock service in golang. Incoming SIP messages are separated by ' ' sequence (I do not care about SDP for now). I want to extract message based on that delimiter and send it over to the processing goroutine. Looking through golang standard libraries I see no trivial way of achieving it. There seems to be no one shop stop in io and bufio packages. Currently I see two options of going forward (bufio):

  1. *Reader.ReadBytes function with '/r' set as the delimiter. Further processing is done by using ReadByte function and comparing it sequentially with each byte of the delimiter and unreading them if necessary (which looks quite tedious)

  2. Using Scanner with a custom split function, which does not look too trivial as well.

I wonder whether there are any other better options, functionality seems so common that it is hard to believe that it is not possible to just define delimiter for tcp stream and extract messages from it.

图片转代码服务由CSDN问答提供 功能建议

我正在研究golang中基于TCP模拟服务的SIP。 传入的SIP消息由' '序列分隔(我现在不在乎SDP)。 我想基于该分隔符提取消息并将其发送到处理goroutine。 查看golang标准库,我发现没有简单的方法可以实现它。 在 io bufio 软件包中似乎没有人会停下来。 当前,我看到前进的两个选项(bufio):

  1. * Reader.ReadBytes函数,其中将'/ r'设置为定界符。 通过使用ReadByte函数并依次将其与定界符的每个字节进行比较,并在需要时不读取它们(看起来很繁琐),来进行进一步处理

  2. 使用带有自定义功能的Scanner 拆分功能,看起来也不是那么琐碎。

    我想知道是否还有其他更好的选择,功能似乎如此普遍,以至于 很难相信,不可能仅为tcp流定义定界符并从中提取消息。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题