github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/whisper/whisperv6/topic.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:46</date>
    10  //</624450125749555200>
    11  
    12  
    13  //包含耳语协议主题元素。
    14  
    15  package whisperv6
    16  
    17  import (
    18  	"github.com/ethereum/go-ethereum/common"
    19  	"github.com/ethereum/go-ethereum/common/hexutil"
    20  )
    21  
    22  //TopicType表示密码安全的概率部分
    23  //消息的分类,确定为
    24  //sha3消息原始作者给出的某些任意数据的散列。
    25  type TopicType [TopicLength]byte
    26  
    27  //BytesToTopic从主题的字节数组表示形式转换
    28  //进入TopicType类型。
    29  func BytesToTopic(b []byte) (t TopicType) {
    30  	sz := TopicLength
    31  	if x := len(b); x < TopicLength {
    32  		sz = x
    33  	}
    34  	for i := 0; i < sz; i++ {
    35  		t[i] = b[i]
    36  	}
    37  	return t
    38  }
    39  
    40  //字符串将主题字节数组转换为字符串表示形式。
    41  func (t *TopicType) String() string {
    42  	return common.ToHex(t[:])
    43  }
    44  
    45  //marshalText返回t的十六进制表示形式。
    46  func (t TopicType) MarshalText() ([]byte, error) {
    47  	return hexutil.Bytes(t[:]).MarshalText()
    48  }
    49  
    50  //UnmarshalText解析主题的十六进制表示。
    51  func (t *TopicType) UnmarshalText(input []byte) error {
    52  	return hexutil.UnmarshalFixedText("Topic", input, t[:])
    53  }
    54