Golang encoding: Difference between revisions
From wikinotes
(Created page with "Golang's <code>encoding</code> module defines the interfaces for data serialization. = Basics = <blockquote> Each method of encoding implements at least one of these interfaces <syntaxhighlight lang="go"> type BinaryMarshaler interface { MarshalBinary() (data []byte, err error) } type BinaryUnmarshaler interface { UnmarshalBinary(data []byte) error } type TextMarshaler interface { MarshallText(text []byte) error } type TextUnmarshaler interface { UnmarshalText(t...") |
No edit summary |
||
Line 17: | Line 17: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</blockquote><!-- Basics --> | </blockquote><!-- Basics --> | ||
= Libraries = | |||
<blockquote> | |||
== Builtin == | |||
<blockquote> | |||
{| | |||
|- | |||
| [[golang encoding/xml]] | |||
|- | |||
|} | |||
</blockquote><!-- Builtin --> | |||
</blockquote><!-- Libraries --> |
Revision as of 02:56, 25 June 2022
Golang's encoding
module defines the interfaces for data serialization.
Basics
Each method of encoding implements at least one of these interfaces
type BinaryMarshaler interface { MarshalBinary() (data []byte, err error) } type BinaryUnmarshaler interface { UnmarshalBinary(data []byte) error } type TextMarshaler interface { MarshallText(text []byte) error } type TextUnmarshaler interface { UnmarshalText(text []byte) error }Rather than a top-down approach, you define types that can be serialized/deserialized.
When deserializing, you cat the type, and deserialization is automatic.
Libraries
Builtin
golang encoding/xml