當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Packet.DecodePayload方法代碼示例

本文整理匯總了Golang中github.com/pdf/golifx/protocol/v2/packet.Packet.DecodePayload方法的典型用法代碼示例。如果您正苦於以下問題:Golang Packet.DecodePayload方法的具體用法?Golang Packet.DecodePayload怎麽用?Golang Packet.DecodePayload使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/pdf/golifx/protocol/v2/packet.Packet的用法示例。


在下文中一共展示了Packet.DecodePayload方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SetStateLabel

func (d *Device) SetStateLabel(pkt *packet.Packet) error {
	l := stateLabel{}
	if err := pkt.DecodePayload(&l); err != nil {
		return err
	}
	common.Log.Debugf("Got label (%v): %+v\n", d.id, l.Label)
	newLabel := stripNull(string(l.Label[:]))
	if newLabel != d.label {
		d.label = newLabel
		if err := d.publish(common.EventUpdateLabel{Label: d.label}); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:chendo,項目名稱:golifx,代碼行數:16,代碼來源:device.go

示例2: SetStateHostFirmware

func (d *Device) SetStateHostFirmware(pkt *packet.Packet) error {
	f := stateHostFirmware{}
	if err := pkt.DecodePayload(&f); err != nil {
		return err
	}
	common.Log.Debugf("Got firmware version (%d): %d", d.id, f.Version)
	d.RLock()
	version := d.firmwareVersion
	d.RUnlock()
	if f.Version != version {
		d.Lock()
		d.firmwareVersion = f.Version
		d.firmwareVersionString = f.String()
		d.Unlock()
	}

	return nil
}
開發者ID:pdf,項目名稱:golifx,代碼行數:18,代碼來源:device.go

示例3: SetStateLabel

func (d *Device) SetStateLabel(pkt *packet.Packet) error {
	l := stateLabel{}
	if err := pkt.DecodePayload(&l); err != nil {
		return err
	}
	common.Log.Debugf("Got label (%d): %v", d.id, string(l.Label[:]))
	newLabel := stripNull(string(l.Label[:]))
	if newLabel != d.CachedLabel() {
		d.Lock()
		d.label = newLabel
		d.Unlock()
		if err := d.publish(common.EventUpdateLabel{Label: newLabel}); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:pdf,項目名稱:golifx,代碼行數:18,代碼來源:device.go

示例4: New

func New(addr *net.UDPAddr, requestSocket *net.UDPConn, timeout *time.Duration, retryInterval *time.Duration, reliable bool, pkt *packet.Packet) (*Device, error) {
	d := new(Device)
	d.init(addr, requestSocket, timeout, retryInterval, reliable)

	if pkt != nil {
		d.id = pkt.Target
		service := new(stateService)

		if err := pkt.DecodePayload(service); err != nil {
			return nil, err
		}

		d.address.Port = int(service.Port)
	}
	go d.handler()

	return d, nil
}
開發者ID:chendo,項目名稱:golifx,代碼行數:18,代碼來源:device.go

示例5: SetStatePower

func (d *Device) SetStatePower(pkt *packet.Packet) error {
	p := statePower{}
	if err := pkt.DecodePayload(&p); err != nil {
		return err
	}
	common.Log.Debugf("Got power (%v): %+v\n", d.id, d.power)

	if d.power != p.Level {
		d.Lock()
		d.power = p.Level
		d.Unlock()
		if err := d.publish(common.EventUpdatePower{Power: d.power > 0}); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:chendo,項目名稱:golifx,代碼行數:18,代碼來源:device.go

示例6: SetStatePower

func (d *Device) SetStatePower(pkt *packet.Packet) error {
	p := statePower{}
	if err := pkt.DecodePayload(&p); err != nil {
		return err
	}
	common.Log.Debugf("Got power (%d): %d", d.id, d.power)

	state := p.Level > 0
	if d.CachedPower() != state {
		d.Lock()
		d.power = p.Level
		d.Unlock()
		if err := d.publish(common.EventUpdatePower{Power: state}); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:pdf,項目名稱:golifx,代碼行數:19,代碼來源:device.go

示例7: Parse

func (g *Group) Parse(pkt *packet.Packet) error {
	var shouldUpdate, labelUpdate bool

	s := stateGroup{}
	if err := pkt.DecodePayload(&s); err != nil {
		return err
	}

	g.RLock()
	if s.UpdatedAt > g.updatedAt {
		shouldUpdate = true
	}
	g.RUnlock()

	if shouldUpdate {
		g.Lock()
		g.id = s.ID
		g.idEncoded = strings.Replace(
			base64.URLEncoding.EncodeToString(s.ID[:]),
			`=`, ``, -1,
		)
		g.updatedAt = s.UpdatedAt
		if g.label != s.Label {
			g.label = s.Label
			labelUpdate = true
		}
		g.Unlock()

		if labelUpdate {
			if err := g.publish(common.EventUpdateLabel{Label: g.GetLabel()}); err != nil {
				return err
			}
		}
	}

	return nil
}
開發者ID:chendo,項目名稱:golifx,代碼行數:37,代碼來源:group.go

示例8: SetState

func (l *Light) SetState(pkt *packet.Packet) error {
	s := &state{}

	if err := pkt.DecodePayload(s); err != nil {
		return err
	}
	common.Log.Debugf("Got light state (%v): %+v\n", l.id, s)

	if l.color != s.Color {
		l.Lock()
		l.color = s.Color
		l.Unlock()
		if err := l.publish(common.EventUpdateColor{Color: l.color}); err != nil {
			return err
		}
	}
	if l.power != s.Power {
		l.Lock()
		l.power = s.Power
		l.Unlock()
		if err := l.publish(common.EventUpdatePower{Power: l.power > 0}); err != nil {
			return err
		}
	}
	newLabel := stripNull(string(s.Label[:]))
	if newLabel != l.label {
		l.Lock()
		l.label = newLabel
		l.Unlock()
		if err := l.publish(common.EventUpdateLabel{Label: l.label}); err != nil {
			return err
		}
	}

	return nil
}
開發者ID:chendo,項目名稱:golifx,代碼行數:36,代碼來源:light.go


注:本文中的github.com/pdf/golifx/protocol/v2/packet.Packet.DecodePayload方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。