如何在Golang中使用UTF-8编码gob?

huangapple go评论81阅读模式
英文:

How to encode gob in UTF-8 in golang ?

问题

我正在使用gob.NewEncoder来编码字符串消息msg,但需要使用utf-8进行编码。

err = gob.NewEncoder(conn).Encode(msg)

我在Ruby接收器(Logstash)中收到一个警告,警告内容是Received an event that has a different character encoding than you configured ...:expected_charset=>"UTF-8"

英文:

I am using gob.NewEncoder to encode string message msg but need to do it in utf-8.

err= gob.NewEncoder(conn).Encode(msg)

I am getting warning in Ruby receiver (Logstash) saying that Received an event that has a different character encoding than you configured ...:expected_charset=>"UTF-8"

答案1

得分: 1

当你调用Encode(msg)时,你并没有发送UTF-8纯文本。

要发送纯文本:

conn.Write([]byte(msg)) // 假设msg是字符串
英文:

When you call Encode(msg), you are not sending UTF-8 plain text.

To send plain text:

conn.Write([]byte(msg)) // suppose msg is string

huangapple
  • 本文由 发表于 2017年1月22日 06:49:00
  • 转载请务必保留本文链接:https://go.coder-hub.com/41785381.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定