英文:
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的示例,但你也可以找到其他类型数据的项目:
-
ajg/form
:用于Go的表单编码和解码包 -
chai2010/protorpc:用于Go的Google Protocol Protobufs RPC
英文:
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:
-
ajg/form
: a Form Encoding & Decoding Package for Go -
chai2010/protorpc: Google Protocol Protobufs RPC for Go
答案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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论