Пример #1
0
func TestGetUint64(t *testing.T) {
	f := frame.NewFrame(FRAME)
	f.Items[SYNC] = frame.NewFrameItem(0, 32)
	f.Items[VERSION] = frame.NewFrameItem(32, 2)
	f.Items[SCID] = frame.NewFrameItem(34, 8)
	f.Items[VCID] = frame.NewFrameItem(42, 6)
	f.Items[VCCNT] = frame.NewFrameItem(48, 24)

	frame := []byte{0x1a, 0xcf, 0xfc, 0x1d, 0x55, 0x57, 0x54, 0x43, 0x21}
	sync, err := f.GetUint64(SYNC, frame)
	if err == nil {
		if sync != uint64(0x1acffc1d) {
			t.Error("expected", sync, "== 0x1acffc1d")
		}
	} else {
		t.Error(err)
	}
	vers, err := f.GetUint64(VERSION, frame)
	if err == nil {
		if vers != uint64(0x01) {
			t.Error("expected", vers, "== 0x01")
		}
	} else {
		t.Error(err)
	}
	scid, err := f.GetUint64(SCID, frame)
	if err == nil {
		if scid != uint64(0x55) {
			t.Error("expected", scid, "== 0x55")
		}
	} else {
		t.Error(err)
	}
	vcid, err := f.GetUint64(VCID, frame)
	if err == nil {
		if vcid != uint64(0x17) {
			t.Error("expected", vcid, "== 0x17")
		}
	} else {
		t.Error(err)
	}
	vccn, err := f.GetUint64(VCCNT, frame)
	if err == nil {
		if vccn != uint64(0x544321) {
			t.Error("expected", vccn, "== 0x544321")
		}
	} else {
		t.Error(err)
	}

	frame = []byte{}
	sync, err = f.GetUint64(SYNC, frame)
	if err == nil {
		t.Error("expected error")
	}
}
Пример #2
0
func Example_getFrame() {
	f := frame.NewFrame("FrameName")
	f.Items["FrameItemName0"] = frame.NewFrameItem(0, 16)
	f.Items["FrameItemName1"] = frame.NewFrameItem(16, 32)

	d := []byte{0x1a, 0xcf, 0xfc, 0x1d}
	value, err := f.GetUint64("FrameItemName0", d)
	if err == nil {
		fmt.Println("value", value)
	} else {
		fmt.Println("err", err)
	}
}
Пример #3
0
func Example_setFrame() {
	f := frame.NewFrame("FrameName")
	f.Items["FrameItemName0"] = frame.NewFrameItem(0, 16)
	f.Items["FrameItemName1"] = frame.NewFrameItem(16, 32)

	d := []byte{0x00, 0x00, 0x00, 0x00}
	value0 := uint64(0x1acf)
	err := f.SetUint64("FrameItemName0", d, value0)
	if err == nil {
		fmt.Println("data", d)
		value1 := uint64(0xfc1d)
		err := f.SetUint64("FrameItemName1", d, value1)
		if err == nil {
			fmt.Println("data", d)
		} else {
			fmt.Println("err", err)
		}
	} else {
		fmt.Println("err", err)
	}
}