2018-11-11 Richard Biener <rguenther@suse.de>
[official-gcc.git] / libgo / go / encoding / encoding.go
blobcc5a53699661d5fc31d2356a1dc33bf18acc0e58
1 // Copyright 2013 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // Package encoding defines interfaces shared by other packages that
6 // convert data to and from byte-level and textual representations.
7 // Packages that check for these interfaces include encoding/gob,
8 // encoding/json, and encoding/xml. As a result, implementing an
9 // interface once can make a type useful in multiple encodings.
10 // Standard types that implement these interfaces include time.Time and net.IP.
11 // The interfaces come in pairs that produce and consume encoded data.
12 package encoding
14 // BinaryMarshaler is the interface implemented by an object that can
15 // marshal itself into a binary form.
17 // MarshalBinary encodes the receiver into a binary form and returns the result.
18 type BinaryMarshaler interface {
19 MarshalBinary() (data []byte, err error)
22 // BinaryUnmarshaler is the interface implemented by an object that can
23 // unmarshal a binary representation of itself.
25 // UnmarshalBinary must be able to decode the form generated by MarshalBinary.
26 // UnmarshalBinary must copy the data if it wishes to retain the data
27 // after returning.
28 type BinaryUnmarshaler interface {
29 UnmarshalBinary(data []byte) error
32 // TextMarshaler is the interface implemented by an object that can
33 // marshal itself into a textual form.
35 // MarshalText encodes the receiver into UTF-8-encoded text and returns the result.
36 type TextMarshaler interface {
37 MarshalText() (text []byte, err error)
40 // TextUnmarshaler is the interface implemented by an object that can
41 // unmarshal a textual representation of itself.
43 // UnmarshalText must be able to decode the form generated by MarshalText.
44 // UnmarshalText must copy the text if it wishes to retain the text
45 // after returning.
46 type TextUnmarshaler interface {
47 UnmarshalText(text []byte) error