github.com/yinchengtsinghua/golang-Eos-dpos-Ethereum@v0.0.0-20190121132951-92cc4225ed8e/whisper/whisperv5/topic.go (about)

     1  
     2  //此源码被清华学神尹成大魔王专业翻译分析并修改
     3  //尹成QQ77025077
     4  //尹成微信18510341407
     5  //尹成所在QQ群721929980
     6  //尹成邮箱 yinc13@mails.tsinghua.edu.cn
     7  //尹成毕业于清华大学,微软区块链领域全球最有价值专家
     8  //https://mvp.microsoft.com/zh-cn/PublicProfile/4033620
     9  //
    10  //
    11  //
    12  //
    13  //
    14  //
    15  //
    16  //
    17  //
    18  //
    19  //
    20  //
    21  //
    22  //
    23  //
    24  
    25  //
    26  
    27  package whisperv5
    28  
    29  import (
    30  	"github.com/ethereum/go-ethereum/common"
    31  	"github.com/ethereum/go-ethereum/common/hexutil"
    32  )
    33  
    34  //
    35  //
    36  //
    37  type TopicType [TopicLength]byte
    38  
    39  func BytesToTopic(b []byte) (t TopicType) {
    40  	sz := TopicLength
    41  	if x := len(b); x < TopicLength {
    42  		sz = x
    43  	}
    44  	for i := 0; i < sz; i++ {
    45  		t[i] = b[i]
    46  	}
    47  	return t
    48  }
    49  
    50  //
    51  func (t *TopicType) String() string {
    52  	return common.ToHex(t[:])
    53  }
    54  
    55  //
    56  func (t TopicType) MarshalText() ([]byte, error) {
    57  	return hexutil.Bytes(t[:]).MarshalText()
    58  }
    59  
    60  //
    61  func (t *TopicType) UnmarshalText(input []byte) error {
    62  	return hexutil.UnmarshalFixedText("Topic", input, t[:])
    63  }