qmpmsg

package
v0.0.0-...-ede35a2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 27, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package qmpmsg defines types used to marshal and umarshal QMP messages.

Index

Constants

View Source
const (
	UnknownMessage = 0
	ReponseMessage = 1
	EventMessage   = 2
)

Message types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Data

type Data struct {
	// contains filtered or unexported fields
}

Data holds raw QMP message data as bytes.

func (*Data) Bytes

func (m *Data) Bytes() []byte

Bytes returns the raw bytes of the data.

func (*Data) UnmarshalJSON

func (m *Data) UnmarshalJSON(b []byte) error

UnmarshalJSON copies the given JSON bytes to m.

type Error

type Error struct {
	Class       string `json:"class"`
	Description string `json:"desc"`
}

Error holds a QMP error returned by a command.

func (Error) Error

func (e Error) Error() string

Error returns the QMP error as a string, so that it can be used as a Go error type.

func (Error) IsZero

func (e Error) IsZero() bool

IsZero returns true if the error is empty.

type Event

type Event struct {
	Event     string    `json:"event"`
	Data      Data      `json:"data,omitempty"`
	Timestamp Timestamp `json:"timestamp"`
}

Event holds an asynchronous event.

type ID

type ID struct {
	Client   uint64
	Sequence uint64
}

ID uniquely identifies a machina QMP request by combining a random 64-bit client identifier with a message sequence number.

func (ID) IsZero

func (id ID) IsZero() bool

IsZero returns true if the ID holds a zero value.

func (ID) MarshalText

func (id ID) MarshalText() (text []byte, err error)

MarshalText marshals the ID as text.

func (ID) String

func (id ID) String() string

String returns a string representation of the ID.

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON attempts to interpret the given JSON data as a machina message ID encoded in a JSON string.

The function always returns a nil error, even if the data does not contain a machina message ID. This is done in case qemu broadcasts responses meant for other clients that use a different message ID format.

type Timestamp

type Timestamp time.Time

Timestamp is a time value that can be umarshaled from a QMP timestamp value encoded in a JSON object.

func (*Timestamp) UnmarshalJSON

func (m *Timestamp) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a QMP timestamp from the given JSON object data.

type Type

type Type int

Type identifies a QMP message type.

func DetectType

func DetectType(msg []byte) Type

DetectType attempts to determine the type of message contained in msg.

If the message is malformed or the type cannot be determined, it returns UnknownMessage.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL