# package encoding
`import "encoding"`
encoding包定义了供其它包使用的可以将数据在字节水平和文本表示之间转换的接口。encoding/gob、encoding/json、encoding/xml三个包都会检查使用这些接口。因此,只要实现了这些接口一次,就可以在多个包里使用。标准包内建类型time.Time和net.IP都实现了这些接口。接口是成对的,分别产生和还原编码后的数据。
## Index
* [type BinaryMarshaler](#BinaryMarshaler)
* [type BinaryUnmarshaler](#BinaryUnmarshaler)
* [type TextMarshaler](#TextMarshaler)
* [type TextUnmarshaler](#TextUnmarshaler)
## type [BinaryMarshaler](https://github.com/golang/go/blob/master/src/encoding/encoding.go#L18 "View Source")
```
type BinaryMarshaler interface {
MarshalBinary() (data []byte, err error)
}
```
实现了BinaryMarshaler接口的类型可以将自身序列化为binary格式。
## type [BinaryUnmarshaler](https://github.com/golang/go/blob/master/src/encoding/encoding.go#L28 "View Source")
```
type BinaryUnmarshaler interface {
UnmarshalBinary(data []byte) error
}
```
实现了BinaryUnmarshaler接口的类型可以将binary格式表示的自身解序列化。
UnmarshalBinary必须可以解码MarshalBinary生成的binary格式数据。本函数可能会对data内容作出修改,所以如果要保持data的数据请事先进行拷贝。
## type [TextMarshaler](https://github.com/golang/go/blob/master/src/encoding/encoding.go#L36 "View Source")
```
type TextMarshaler interface {
MarshalText() (text []byte, err error)
}
```
实现了BinaryMarshaler接口的类型可以将自身序列化为utf-8编码的textual格式。
## type [TextUnmarshaler](https://github.com/golang/go/blob/master/src/encoding/encoding.go#L46 "View Source")
```
type TextUnmarshaler interface {
UnmarshalText(text []byte) error
}
```
实现了TextUnmarshaler接口的类型可以将textual格式表示的自身解序列化。
UnmarshalText必须可以解码MarshalText生成的textual格式数据。本函数可能会对data内容作出修改,所以如果要保持data的数据请事先进行拷贝。
- 库
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe