Exemplo n.º 1
0
func NewPacket(command uint16, payload interface{}) *Packet {
	inst := &Packet{
		Command: command,
		ID:      consistenthash.NewRandomKey(),
		Sent:    time.Now(),
		Payload: payload,
	}
	return inst
}
Exemplo n.º 2
0
func NewResponsePacket(command uint16, requestid [16]byte, payload interface{}) *Packet {
	inst := &Packet{
		Command:   command,
		ID:        [16]byte(consistenthash.NewRandomKey()),
		RequestID: requestid,
		Sent:      time.Now(),
		Payload:   payload,
	}
	return inst
}
Exemplo n.º 3
0
func TestNewResponsePacket(t *testing.T) {
	payload := "Test2"

	k1 := [16]byte(consistenthash.NewRandomKey())
	inst := NewResponsePacket(CMD_DISTRIBUTION, k1, payload)

	assert.Equal(t, inst.Command, uint16(CMD_DISTRIBUTION))
	assert.NotNil(t, inst.ID)
	assert.NotNil(t, inst.RequestID, k1)
	assert.NotNil(t, inst.Sent)
	assert.Equal(t, inst.Payload, payload)
}