Esempio n. 1
0
func updateEqual(update mojom.Update, ad mojom.Advertisement) bool {
	if got, _ := update.GetId(); got != *ad.Id {
		return false
	}
	if got, _ := update.GetInterfaceName(); got != ad.InterfaceName {
		return false
	}
	if got, _ := update.GetAddresses(); !reflect.DeepEqual(got, ad.Addresses) {
		return false
	}
	if ad.Attributes != nil {
		for k, v := range *ad.Attributes {
			if got, _ := update.GetAttribute(k); got != v {
				return false
			}
		}
	}
	if ad.Attachments != nil {
		for k, v := range *ad.Attachments {
			h, err := update.GetAttachment(k)
			if err != nil {
				return false
			}
			defer h.Close()
			h.Wait(system.MOJO_HANDLE_SIGNAL_READABLE, system.MOJO_DEADLINE_INDEFINITE)
			r, got := h.ReadData(system.MOJO_READ_DATA_FLAG_ALL_OR_NONE)
			if r != system.MOJO_RESULT_OK {
				return false
			}
			if !bytes.Equal(got, v) {
				return false
			}
		}
	}
	return true
}
Esempio n. 2
0
func updateToDebugString(update mojom.Update) string {
	lost, _ := update.IsLost()
	ad, _ := update.GetAdvertisement()
	return fmt.Sprintf("{%v, %v}", lost, strings.Join(dumpFields(ad), ", "))
}