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