github.com/anacrolix/torrent@v1.61.0/types/peerid.go (about)

     1  package types
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  )
     7  
     8  // Peer client ID.
     9  type PeerID [20]byte
    10  
    11  //var _ slog.LogValuer = PeerID{}
    12  
    13  func (me PeerID) String() string {
    14  	return fmt.Sprintf("%+q", me[:])
    15  }
    16  
    17  //
    18  //func (me PeerID) LogValue() slog.Value {
    19  //	return slog.StringValue(fmt.Sprintf("%+q", me[:]))
    20  //}
    21  
    22  func (me PeerID) MarshalJSON() ([]byte, error) {
    23  	return json.Marshal(me.String())
    24  }
    25  
    26  // // Pretty prints the ID as hex, except parts that adhere to the PeerInfo ID
    27  // // Conventions of BEP 20.
    28  // func (me PeerID) String() string {
    29  // 	// if me[0] == '-' && me[7] == '-' {
    30  // 	// 	return string(me[:8]) + hex.EncodeToString(me[8:])
    31  // 	// }
    32  // 	// return hex.EncodeToString(me[:])
    33  // 	return fmt.Sprintf("%+q", me[:])
    34  // }