Example #1
0
func TestConversion(t *testing.T) {
	buf := make([]byte, 8)
	message.Uint64ToByteArray(buf, testId)
	id := message.ByteArrayToUint64(buf)
	assert.Equal(t, testId, id, "uint64 conversion is wrong!")

	buf = make([]byte, 4)
	message.Uint32ToByteArray(buf, testNum)
	n := message.ByteArrayToUint32(buf)
	assert.Equal(t, testNum, n, "uint32 conversion is wrong!")

	a1 := message.Uint64ArrayToByteArray(nil)
	a2 := message.Uint64ArrayToByteArray(make([]uint64, 0))
	a3 := message.Uint64ArrayToByteArray(testList)

	assert.Nil(t, a1, "Should return nil with nil as input")
	assert.Len(t, a2, 0, "Should give empty byte list")
	assert.Len(t, a3, len(testList)*8, "One element takes 8 bytes of space")

	l1 := message.ByteArrayToUint64Array(nil)
	l2 := message.ByteArrayToUint64Array(make([]byte, 7))
	l3 := message.ByteArrayToUint64Array(make([]byte, 0))
	l4 := message.ByteArrayToUint64Array(a3)

	assert.Nil(t, l1, "Should return nil with nil as input")
	assert.Nil(t, l2, "Should return nil with incorrect length")
	assert.Len(t, l3, 0, "Should give empty byte list")
	assert.Nil(t, testutils.CompareList(l4, testList), "Lists should be the same")
}
Example #2
0
func (bucket *StatBucket) FromByteArray(arr []byte) {

	values := message.ByteArrayToUint64Array(arr)

	bucket.TimeAlive.Set(values[0])
	bucket.ClientsConnected.Set(values[1])
	bucket.ClientsDisconnected.Set(values[2])
	bucket.IncomingMessages.Set(values[3])
	bucket.OutgoingMessages.Set(values[4])
	bucket.ByteRead.Set(values[5])
	bucket.ByteWritten.Set(values[6])
}
Example #3
0
func BenchmarkUint64ArrayToByteArray(b *testing.B) {
	for n := 0; n < b.N; n++ {
		message.ByteArrayToUint64Array(testListByte)
	}
}