File: update3.go

package info (click to toggle)
golang-github-ovn-org-libovsdb 0.7.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, forky, sid, trixie
  • size: 1,440 kB
  • sloc: makefile: 52; sh: 14
file content (51 lines) | stat: -rw-r--r-- 974 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package ovsdb

import (
	"encoding/json"
	"fmt"
)

type MonitorCondSinceReply struct {
	Found             bool
	LastTransactionID string
	Updates           TableUpdates2
}

func (m MonitorCondSinceReply) MarshalJSON() ([]byte, error) {
	v := []interface{}{m.Found, m.LastTransactionID, m.Updates}
	return json.Marshal(v)
}

func (m *MonitorCondSinceReply) UnmarshalJSON(b []byte) error {
	var v []json.RawMessage
	err := json.Unmarshal(b, &v)
	if err != nil {
		return err
	}
	if len(v) != 3 {
		return fmt.Errorf("expected a 3 element json array. there are %d elements", len(v))
	}

	var found bool
	err = json.Unmarshal(v[0], &found)
	if err != nil {
		return err
	}

	var lastTransactionID string
	err = json.Unmarshal(v[1], &lastTransactionID)
	if err != nil {
		return err
	}

	var updates TableUpdates2
	err = json.Unmarshal(v[2], &updates)
	if err != nil {
		return err
	}

	m.Found = found
	m.LastTransactionID = lastTransactionID
	m.Updates = updates
	return nil
}