Go语言是否有像PHP一样的序列化功能?

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

Does Go have serialization like php?

问题

Go语言是否有像PHP函数serialize()那样的纯文本结果的序列化功能?

字符串
s:size:value;

整数
i:value;

布尔值
b:value;(不存储"true"或"false",而是存储'1'或'0')

空值
N;

数组
a:size:{key definition;value definition;(每个元素重复)}

英文:

Does Go have serialization with plain text result like PHP function serialize()?

String
s:size:value;

Integer
i:value;

Boolean
b:value; (does not store "true" or "false", does store '1' or '0')

Null
N;

Array
a:size:{key definition;value definition;(repeated per element)}

答案1

得分: 1

php.serialize最接近的功能可能是encoding package,它具有MarshalText() / UnmarshalText()等方法:任何实现TextMarshaler/TextUnmarshaler接口的对象都可以进行序列化。(对于二进制的编组/解组,也有相同的功能)

你可以查看JSON的示例,但你也可以找到其他类型数据的项目:

英文:

The closest of php.serialize would be the encoding package with methods like MarshalText() / UnmarshalText(): any object implementing the interface TextMarshaler/TextUnmarshaler would be serializable.
(And you have the same feature for binary marshal/unmarshal)

You can see examples for JSON, but you can find other projects for other type of data:

答案2

得分: 1

好的,以下是翻译好的内容:

嗯,并不完全准确。

gob,它是二进制的,或者你可以使用json(与php的json_encode / json_decode相同)。

对于跨语言(二进制)解决方案,有几个选项:

英文:

Well, not exactly.

There's gob which is binary, or you can use json (same as php's json_encode / json_decode.

For cross-language (binary) solutions there're few options:

huangapple
  • 本文由 发表于 2014年11月16日 06:30:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/26951494.html
匿名

发表评论

匿名网友

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

确定