Пример #1
0
package coap

import (
	"bytes"
	"encoding"
	"fmt"
	"reflect"
	"testing"
)

var (
	_ = encoding.BinaryMarshaler(&Message{})
	_ = encoding.BinaryUnmarshaler(&Message{})
)

// assertEqualMessages compares the e(xptected) message to the a(ctual) message
// and reports any diffs with t.Errorf.
func assertEqualMessages(t *testing.T, e, a Message) {
	if e.Type != a.Type {
		t.Errorf("Expected type %v, got %v", e.Type, a.Type)
	}
	if e.Code != a.Code {
		t.Errorf("Expected code %v, got %v", e.Code, a.Code)
	}
	if e.MessageID != a.MessageID {
		t.Errorf("Expected MessageID %v, got %v", e.MessageID, a.MessageID)
	}
	if !bytes.Equal(e.Token, a.Token) {
		t.Errorf("Expected token %#v, got %#v", e.Token, a.Token)
	}
	if !bytes.Equal(e.Payload, a.Payload) {
Пример #2
0
// Clock is a logical clock.
//
// The zero value is a valid empty clock, but most callers should call
// Create to get the creation time set up.
type Clock struct {
	sync vector
	mod  vector
	// create is always of length 1
	//
	// TODO could make it an item not a vector, but then we can't
	// use compareLE.
	create vector
}

var _ = encoding.BinaryMarshaler(&Clock{})
var _ = encoding.BinaryUnmarshaler(&Clock{})

// Create returns a new Vector Pair that knows it was created by id at
// time now.
func Create(id Peer, now Epoch) *Clock {
	c := &Clock{
		sync:   vector{list: []item{{id: id, t: now}}},
		mod:    vector{list: []item{{id: id, t: now}}},
		create: vector{list: []item{{id: id, t: now}}},
	}
	return c
}

// Update adds or updates the version vector entry for id to point to
// time now.