pDHTMessage.go 730 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11
package dht

// A helper struct to make working with protbuf types easier
type pDHTMessage struct {
	Type DHTMessage_MessageType
	Key string
	Value []byte
	Response bool
	Id uint64
}

12 13 14 15 16 17 18 19 20 21 22
var mesNames [10]string

func init() {
	mesNames[DHTMessage_ADD_PROVIDER] = "add provider"
	mesNames[DHTMessage_FIND_NODE] = "find node"
	mesNames[DHTMessage_GET_PROVIDERS] = "get providers"
	mesNames[DHTMessage_GET_VALUE] = "get value"
	mesNames[DHTMessage_PUT_VALUE] = "put value"
	mesNames[DHTMessage_PING] = "ping"
}

23 24 25 26 27 28 29 30 31 32 33 34 35
func (m *pDHTMessage) ToProtobuf() *DHTMessage {
	pmes := new(DHTMessage)
	if m.Value != nil {
		pmes.Value = m.Value
	}

	pmes.Type = &m.Type
	pmes.Key = &m.Key
	pmes.Response = &m.Response
	pmes.Id = &m.Id

	return pmes
}