github.com/linapex/ethereum-dpos-chinese@v0.0.0-20190316121959-b78b3a4a1ece/whisper/whisperv5/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 12:09:51</date>
    10  //</624342689420152832>
    11  
    12  //
    13  //
    14  //
    15  //
    16  //
    17  //
    18  //
    19  //
    20  //
    21  //
    22  //
    23  //
    24  //
    25  //
    26  //
    27  
    28  //
    29  
    30  package whisperv5
    31  
    32  import (
    33  	"github.com/ethereum/go-ethereum/common"
    34  	"github.com/ethereum/go-ethereum/common/hexutil"
    35  )
    36  
    37  //
    38  //
    39  //
    40  type TopicType [TopicLength]byte
    41  
    42  func BytesToTopic(b []byte) (t TopicType) {
    43  	sz := TopicLength
    44  	if x := len(b); x < TopicLength {
    45  		sz = x
    46  	}
    47  	for i := 0; i < sz; i++ {
    48  		t[i] = b[i]
    49  	}
    50  	return t
    51  }
    52  
    53  //
    54  func (t *TopicType) String() string {
    55  	return common.ToHex(t[:])
    56  }
    57  
    58  //
    59  func (t TopicType) MarshalText() ([]byte, error) {
    60  	return hexutil.Bytes(t[:]).MarshalText()
    61  }
    62  
    63  //
    64  func (t *TopicType) UnmarshalText(input []byte) error {
    65  	return hexutil.UnmarshalFixedText("Topic", input, t[:])
    66  }
    67