docs(README): modify readme

This commit is contained in:
Overbool 2018-09-14 22:13:04 +08:00
parent d6ad8896de
commit c7b4679a01
1 changed files with 12 additions and 2 deletions

View File

@ -73,9 +73,19 @@ m1.Protocols()
#### En/decapsulate #### En/decapsulate
```go ```go
m.Encapsulate(ma.NewMultiaddr("/sctp/5678")) import ma "github.com/multiformats/go-multiaddr"
m, err := ma.NewMultiaddr("/ip4/127.0.0.1/udp/1234")
// <Multiaddr /ip4/127.0.0.1/udp/1234>
sctpMA, err := ma.NewMultiaddr("/sctp/5678")
m.Encapsulate(sctpMA)
// <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678> // <Multiaddr /ip4/127.0.0.1/udp/1234/sctp/5678>
m.Decapsulate(ma.NewMultiaddr("/udp")) // up to + inc last occurrence of subaddr
udpMA, err := ma.NewMultiaddr("/udp/1234")
m.Decapsulate(udpMA) // up to + inc last occurrence of subaddr
// <Multiaddr /ip4/127.0.0.1> // <Multiaddr /ip4/127.0.0.1>
``` ```