mirror of
https://github.com/hanzoai/iris.git
synced 2026-11-09 15:47:54 +00:00
900 lines
23 KiB
Go
900 lines
23 KiB
Go
// Code generated by zapgen; DO NOT EDIT.
|
|
// source: iris.zap
|
|
|
|
package iris
|
|
|
|
import (
|
|
"fmt"
|
|
zap "github.com/zap-proto/go"
|
|
"github.com/zap-proto/go/rpc"
|
|
)
|
|
|
|
const (
|
|
helloWOff = 0
|
|
helloHOff = 2
|
|
helloDprOff = 4
|
|
helloCreditOff = 8
|
|
helloSize = 9
|
|
)
|
|
|
|
// Hello is a zero-copy view into a ZAP-encoded Hello message.
|
|
type Hello struct{ o zap.Object }
|
|
|
|
// WrapHello parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapHello(b []byte) (Hello, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Hello{}, err
|
|
}
|
|
return Hello{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Hello) W() uint16 { return t.o.Uint16(helloWOff) }
|
|
func (t Hello) H() uint16 { return t.o.Uint16(helloHOff) }
|
|
func (t Hello) Dpr() float32 { return t.o.Float32(helloDprOff) }
|
|
func (t Hello) Credit() uint8 { return t.o.Uint8(helloCreditOff) }
|
|
|
|
// HelloInput collects the field values for NewHello.
|
|
type HelloInput struct {
|
|
W uint16
|
|
H uint16
|
|
Dpr float32
|
|
Credit uint8
|
|
}
|
|
|
|
// NewHello builds a ZAP-encoded Hello message from in and returns the bytes.
|
|
func NewHello(in HelloInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(helloSize)
|
|
ob.SetUint16(helloWOff, in.W)
|
|
ob.SetUint16(helloHOff, in.H)
|
|
ob.SetFloat32(helloDprOff, in.Dpr)
|
|
ob.SetUint8(helloCreditOff, in.Credit)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
creditSeqOff = 0
|
|
creditNOff = 4
|
|
creditDecodeUsOff = 5
|
|
creditSize = 9
|
|
)
|
|
|
|
// Credit is a zero-copy view into a ZAP-encoded Credit message.
|
|
type Credit struct{ o zap.Object }
|
|
|
|
// WrapCredit parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapCredit(b []byte) (Credit, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Credit{}, err
|
|
}
|
|
return Credit{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Credit) Seq() uint32 { return t.o.Uint32(creditSeqOff) }
|
|
func (t Credit) N() uint8 { return t.o.Uint8(creditNOff) }
|
|
func (t Credit) DecodeUs() uint32 { return t.o.Uint32(creditDecodeUsOff) }
|
|
|
|
// CreditInput collects the field values for NewCredit.
|
|
type CreditInput struct {
|
|
Seq uint32
|
|
N uint8
|
|
DecodeUs uint32
|
|
}
|
|
|
|
// NewCredit builds a ZAP-encoded Credit message from in and returns the bytes.
|
|
func NewCredit(in CreditInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(creditSize)
|
|
ob.SetUint32(creditSeqOff, in.Seq)
|
|
ob.SetUint8(creditNOff, in.N)
|
|
ob.SetUint32(creditDecodeUsOff, in.DecodeUs)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
pointerXOff = 0
|
|
pointerYOff = 2
|
|
pointerButtonsOff = 4
|
|
pointerModsOff = 5
|
|
pointerSize = 6
|
|
)
|
|
|
|
// Pointer is a zero-copy view into a ZAP-encoded Pointer message.
|
|
type Pointer struct{ o zap.Object }
|
|
|
|
// WrapPointer parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapPointer(b []byte) (Pointer, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Pointer{}, err
|
|
}
|
|
return Pointer{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Pointer) X() uint16 { return t.o.Uint16(pointerXOff) }
|
|
func (t Pointer) Y() uint16 { return t.o.Uint16(pointerYOff) }
|
|
func (t Pointer) Buttons() uint8 { return t.o.Uint8(pointerButtonsOff) }
|
|
func (t Pointer) Mods() uint8 { return t.o.Uint8(pointerModsOff) }
|
|
|
|
// PointerInput collects the field values for NewPointer.
|
|
type PointerInput struct {
|
|
X uint16
|
|
Y uint16
|
|
Buttons uint8
|
|
Mods uint8
|
|
}
|
|
|
|
// NewPointer builds a ZAP-encoded Pointer message from in and returns the bytes.
|
|
func NewPointer(in PointerInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(pointerSize)
|
|
ob.SetUint16(pointerXOff, in.X)
|
|
ob.SetUint16(pointerYOff, in.Y)
|
|
ob.SetUint8(pointerButtonsOff, in.Buttons)
|
|
ob.SetUint8(pointerModsOff, in.Mods)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
wheelXOff = 0
|
|
wheelYOff = 2
|
|
wheelDxOff = 4
|
|
wheelDyOff = 6
|
|
wheelModsOff = 8
|
|
wheelSize = 9
|
|
)
|
|
|
|
// Wheel is a zero-copy view into a ZAP-encoded Wheel message.
|
|
type Wheel struct{ o zap.Object }
|
|
|
|
// WrapWheel parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapWheel(b []byte) (Wheel, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Wheel{}, err
|
|
}
|
|
return Wheel{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Wheel) X() uint16 { return t.o.Uint16(wheelXOff) }
|
|
func (t Wheel) Y() uint16 { return t.o.Uint16(wheelYOff) }
|
|
func (t Wheel) Dx() int16 { return t.o.Int16(wheelDxOff) }
|
|
func (t Wheel) Dy() int16 { return t.o.Int16(wheelDyOff) }
|
|
func (t Wheel) Mods() uint8 { return t.o.Uint8(wheelModsOff) }
|
|
|
|
// WheelInput collects the field values for NewWheel.
|
|
type WheelInput struct {
|
|
X uint16
|
|
Y uint16
|
|
Dx int16
|
|
Dy int16
|
|
Mods uint8
|
|
}
|
|
|
|
// NewWheel builds a ZAP-encoded Wheel message from in and returns the bytes.
|
|
func NewWheel(in WheelInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(wheelSize)
|
|
ob.SetUint16(wheelXOff, in.X)
|
|
ob.SetUint16(wheelYOff, in.Y)
|
|
ob.SetUint16(wheelDxOff, uint16(in.Dx))
|
|
ob.SetUint16(wheelDyOff, uint16(in.Dy))
|
|
ob.SetUint8(wheelModsOff, in.Mods)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
keySymOff = 0
|
|
keyCodeOff = 4
|
|
keyDownOff = 6
|
|
keyModsOff = 7
|
|
keySize = 8
|
|
)
|
|
|
|
// Key is a zero-copy view into a ZAP-encoded Key message.
|
|
type Key struct{ o zap.Object }
|
|
|
|
// WrapKey parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapKey(b []byte) (Key, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Key{}, err
|
|
}
|
|
return Key{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Key) Sym() uint32 { return t.o.Uint32(keySymOff) }
|
|
func (t Key) Code() uint16 { return t.o.Uint16(keyCodeOff) }
|
|
func (t Key) Down() bool { return t.o.Bool(keyDownOff) }
|
|
func (t Key) Mods() uint8 { return t.o.Uint8(keyModsOff) }
|
|
|
|
// KeyInput collects the field values for NewKey.
|
|
type KeyInput struct {
|
|
Sym uint32
|
|
Code uint16
|
|
Down bool
|
|
Mods uint8
|
|
}
|
|
|
|
// NewKey builds a ZAP-encoded Key message from in and returns the bytes.
|
|
func NewKey(in KeyInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(keySize)
|
|
ob.SetUint32(keySymOff, in.Sym)
|
|
ob.SetUint16(keyCodeOff, in.Code)
|
|
ob.SetBool(keyDownOff, in.Down)
|
|
ob.SetUint8(keyModsOff, in.Mods)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
commitTextOff = 0
|
|
commitSize = 8
|
|
)
|
|
|
|
// Commit is a zero-copy view into a ZAP-encoded Commit message.
|
|
type Commit struct{ o zap.Object }
|
|
|
|
// WrapCommit parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapCommit(b []byte) (Commit, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Commit{}, err
|
|
}
|
|
return Commit{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Commit) Text() string { return t.o.Text(commitTextOff) }
|
|
|
|
// CommitInput collects the field values for NewCommit.
|
|
type CommitInput struct {
|
|
Text string
|
|
}
|
|
|
|
// NewCommit builds a ZAP-encoded Commit message from in and returns the bytes.
|
|
func NewCommit(in CommitInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(commitSize)
|
|
ob.SetText(commitTextOff, in.Text)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
resizeWOff = 0
|
|
resizeHOff = 2
|
|
resizeDprOff = 4
|
|
resizeSize = 8
|
|
)
|
|
|
|
// Resize is a zero-copy view into a ZAP-encoded Resize message.
|
|
type Resize struct{ o zap.Object }
|
|
|
|
// WrapResize parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapResize(b []byte) (Resize, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Resize{}, err
|
|
}
|
|
return Resize{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Resize) W() uint16 { return t.o.Uint16(resizeWOff) }
|
|
func (t Resize) H() uint16 { return t.o.Uint16(resizeHOff) }
|
|
func (t Resize) Dpr() float32 { return t.o.Float32(resizeDprOff) }
|
|
|
|
// ResizeInput collects the field values for NewResize.
|
|
type ResizeInput struct {
|
|
W uint16
|
|
H uint16
|
|
Dpr float32
|
|
}
|
|
|
|
// NewResize builds a ZAP-encoded Resize message from in and returns the bytes.
|
|
func NewResize(in ResizeInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(resizeSize)
|
|
ob.SetUint16(resizeWOff, in.W)
|
|
ob.SetUint16(resizeHOff, in.H)
|
|
ob.SetFloat32(resizeDprOff, in.Dpr)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
refreshQOff = 0
|
|
refreshSize = 1
|
|
)
|
|
|
|
// Refresh is a zero-copy view into a ZAP-encoded Refresh message.
|
|
type Refresh struct{ o zap.Object }
|
|
|
|
// WrapRefresh parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapRefresh(b []byte) (Refresh, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Refresh{}, err
|
|
}
|
|
return Refresh{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Refresh) Q() uint8 { return t.o.Uint8(refreshQOff) }
|
|
|
|
// RefreshInput collects the field values for NewRefresh.
|
|
type RefreshInput struct {
|
|
Q uint8
|
|
}
|
|
|
|
// NewRefresh builds a ZAP-encoded Refresh message from in and returns the bytes.
|
|
func NewRefresh(in RefreshInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(refreshSize)
|
|
ob.SetUint8(refreshQOff, in.Q)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
pickTargetOff = 0
|
|
pickSize = 8
|
|
)
|
|
|
|
// Pick is a zero-copy view into a ZAP-encoded Pick message.
|
|
type Pick struct{ o zap.Object }
|
|
|
|
// WrapPick parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapPick(b []byte) (Pick, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Pick{}, err
|
|
}
|
|
return Pick{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Pick) Target() string { return t.o.Text(pickTargetOff) }
|
|
|
|
// PickInput collects the field values for NewPick.
|
|
type PickInput struct {
|
|
Target string
|
|
}
|
|
|
|
// NewPick builds a ZAP-encoded Pick message from in and returns the bytes.
|
|
func NewPick(in PickInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(pickSize)
|
|
ob.SetText(pickTargetOff, in.Target)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
filesPathsOff = 0
|
|
filesSize = 8
|
|
)
|
|
|
|
// Files is a zero-copy view into a ZAP-encoded Files message.
|
|
type Files struct{ o zap.Object }
|
|
|
|
// WrapFiles parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapFiles(b []byte) (Files, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Files{}, err
|
|
}
|
|
return Files{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Files) Paths() zap.List { return t.o.List(filesPathsOff) }
|
|
|
|
// FilesInput collects the field values for NewFiles.
|
|
type FilesInput struct {
|
|
Paths [][]byte
|
|
}
|
|
|
|
// NewFiles builds a ZAP-encoded Files message from in and returns the bytes.
|
|
func NewFiles(in FilesInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(filesSize)
|
|
pathsLB := b.StartList(0)
|
|
for _, elem := range in.Paths {
|
|
pathsLB.AddObjectBytes(elem)
|
|
}
|
|
ob.SetList(filesPathsOff, pathsLB.FinishOffset(), len(in.Paths))
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
clipTextOff = 0
|
|
clipSize = 8
|
|
)
|
|
|
|
// Clip is a zero-copy view into a ZAP-encoded Clip message.
|
|
type Clip struct{ o zap.Object }
|
|
|
|
// WrapClip parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapClip(b []byte) (Clip, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Clip{}, err
|
|
}
|
|
return Clip{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Clip) Text() string { return t.o.Text(clipTextOff) }
|
|
|
|
// ClipInput collects the field values for NewClip.
|
|
type ClipInput struct {
|
|
Text string
|
|
}
|
|
|
|
// NewClip builds a ZAP-encoded Clip message from in and returns the bytes.
|
|
func NewClip(in ClipInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(clipSize)
|
|
ob.SetText(clipTextOff, in.Text)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
cdpIdOff = 0
|
|
cdpJsonOff = 4
|
|
cdpSize = 12
|
|
)
|
|
|
|
// Cdp is a zero-copy view into a ZAP-encoded Cdp message.
|
|
type Cdp struct{ o zap.Object }
|
|
|
|
// WrapCdp parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapCdp(b []byte) (Cdp, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Cdp{}, err
|
|
}
|
|
return Cdp{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Cdp) Id() uint32 { return t.o.Uint32(cdpIdOff) }
|
|
func (t Cdp) Json() string { return t.o.Text(cdpJsonOff) }
|
|
|
|
// CdpInput collects the field values for NewCdp.
|
|
type CdpInput struct {
|
|
Id uint32
|
|
Json string
|
|
}
|
|
|
|
// NewCdp builds a ZAP-encoded Cdp message from in and returns the bytes.
|
|
func NewCdp(in CdpInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(cdpSize)
|
|
ob.SetUint32(cdpIdOff, in.Id)
|
|
ob.SetText(cdpJsonOff, in.Json)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
sizeWOff = 0
|
|
sizeHOff = 2
|
|
sizeDprOff = 4
|
|
sizeModeOff = 8
|
|
sizeSize = 9
|
|
)
|
|
|
|
// Size is a zero-copy view into a ZAP-encoded Size message.
|
|
type Size struct{ o zap.Object }
|
|
|
|
// WrapSize parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapSize(b []byte) (Size, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Size{}, err
|
|
}
|
|
return Size{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Size) W() uint16 { return t.o.Uint16(sizeWOff) }
|
|
func (t Size) H() uint16 { return t.o.Uint16(sizeHOff) }
|
|
func (t Size) Dpr() float32 { return t.o.Float32(sizeDprOff) }
|
|
func (t Size) Mode() uint8 { return t.o.Uint8(sizeModeOff) }
|
|
|
|
// SizeInput collects the field values for NewSize.
|
|
type SizeInput struct {
|
|
W uint16
|
|
H uint16
|
|
Dpr float32
|
|
Mode uint8
|
|
}
|
|
|
|
// NewSize builds a ZAP-encoded Size message from in and returns the bytes.
|
|
func NewSize(in SizeInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(sizeSize)
|
|
ob.SetUint16(sizeWOff, in.W)
|
|
ob.SetUint16(sizeHOff, in.H)
|
|
ob.SetFloat32(sizeDprOff, in.Dpr)
|
|
ob.SetUint8(sizeModeOff, in.Mode)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
tileSeqOff = 0
|
|
tileXOff = 4
|
|
tileYOff = 6
|
|
tileWOff = 8
|
|
tileHOff = 10
|
|
tileQOff = 12
|
|
tileLastOff = 13
|
|
tileJpegOff = 14
|
|
tileSize = 22
|
|
)
|
|
|
|
// Tile is a zero-copy view into a ZAP-encoded Tile message.
|
|
type Tile struct{ o zap.Object }
|
|
|
|
// WrapTile parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapTile(b []byte) (Tile, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Tile{}, err
|
|
}
|
|
return Tile{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Tile) Seq() uint32 { return t.o.Uint32(tileSeqOff) }
|
|
func (t Tile) X() uint16 { return t.o.Uint16(tileXOff) }
|
|
func (t Tile) Y() uint16 { return t.o.Uint16(tileYOff) }
|
|
func (t Tile) W() uint16 { return t.o.Uint16(tileWOff) }
|
|
func (t Tile) H() uint16 { return t.o.Uint16(tileHOff) }
|
|
func (t Tile) Q() uint8 { return t.o.Uint8(tileQOff) }
|
|
func (t Tile) Last() bool { return t.o.Bool(tileLastOff) }
|
|
func (t Tile) Jpeg() []byte { return t.o.Bytes(tileJpegOff) }
|
|
|
|
// TileInput collects the field values for NewTile.
|
|
type TileInput struct {
|
|
Seq uint32
|
|
X uint16
|
|
Y uint16
|
|
W uint16
|
|
H uint16
|
|
Q uint8
|
|
Last bool
|
|
Jpeg []byte
|
|
}
|
|
|
|
// NewTile builds a ZAP-encoded Tile message from in and returns the bytes.
|
|
func NewTile(in TileInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(tileSize)
|
|
ob.SetUint32(tileSeqOff, in.Seq)
|
|
ob.SetUint16(tileXOff, in.X)
|
|
ob.SetUint16(tileYOff, in.Y)
|
|
ob.SetUint16(tileWOff, in.W)
|
|
ob.SetUint16(tileHOff, in.H)
|
|
ob.SetUint8(tileQOff, in.Q)
|
|
ob.SetBool(tileLastOff, in.Last)
|
|
ob.SetBytes(tileJpegOff, in.Jpeg)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
cursorCssOff = 0
|
|
cursorWOff = 8
|
|
cursorHOff = 10
|
|
cursorHxOff = 12
|
|
cursorHyOff = 14
|
|
cursorRgbaOff = 16
|
|
cursorSize = 24
|
|
)
|
|
|
|
// Cursor is a zero-copy view into a ZAP-encoded Cursor message.
|
|
type Cursor struct{ o zap.Object }
|
|
|
|
// WrapCursor parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapCursor(b []byte) (Cursor, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Cursor{}, err
|
|
}
|
|
return Cursor{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Cursor) Css() string { return t.o.Text(cursorCssOff) }
|
|
func (t Cursor) W() uint16 { return t.o.Uint16(cursorWOff) }
|
|
func (t Cursor) H() uint16 { return t.o.Uint16(cursorHOff) }
|
|
func (t Cursor) Hx() uint16 { return t.o.Uint16(cursorHxOff) }
|
|
func (t Cursor) Hy() uint16 { return t.o.Uint16(cursorHyOff) }
|
|
func (t Cursor) Rgba() []byte { return t.o.Bytes(cursorRgbaOff) }
|
|
|
|
// CursorInput collects the field values for NewCursor.
|
|
type CursorInput struct {
|
|
Css string
|
|
W uint16
|
|
H uint16
|
|
Hx uint16
|
|
Hy uint16
|
|
Rgba []byte
|
|
}
|
|
|
|
// NewCursor builds a ZAP-encoded Cursor message from in and returns the bytes.
|
|
func NewCursor(in CursorInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(cursorSize)
|
|
ob.SetText(cursorCssOff, in.Css)
|
|
ob.SetUint16(cursorWOff, in.W)
|
|
ob.SetUint16(cursorHOff, in.H)
|
|
ob.SetUint16(cursorHxOff, in.Hx)
|
|
ob.SetUint16(cursorHyOff, in.Hy)
|
|
ob.SetBytes(cursorRgbaOff, in.Rgba)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
pointXOff = 0
|
|
pointYOff = 2
|
|
pointSize = 4
|
|
)
|
|
|
|
// Point is a zero-copy view into a ZAP-encoded Point message.
|
|
type Point struct{ o zap.Object }
|
|
|
|
// WrapPoint parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapPoint(b []byte) (Point, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Point{}, err
|
|
}
|
|
return Point{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Point) X() uint16 { return t.o.Uint16(pointXOff) }
|
|
func (t Point) Y() uint16 { return t.o.Uint16(pointYOff) }
|
|
|
|
// PointInput collects the field values for NewPoint.
|
|
type PointInput struct {
|
|
X uint16
|
|
Y uint16
|
|
}
|
|
|
|
// NewPoint builds a ZAP-encoded Point message from in and returns the bytes.
|
|
func NewPoint(in PointInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(pointSize)
|
|
ob.SetUint16(pointXOff, in.X)
|
|
ob.SetUint16(pointYOff, in.Y)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
wantKindOff = 0
|
|
wantManyOff = 1
|
|
wantSize = 2
|
|
)
|
|
|
|
// Want is a zero-copy view into a ZAP-encoded Want message.
|
|
type Want struct{ o zap.Object }
|
|
|
|
// WrapWant parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapWant(b []byte) (Want, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Want{}, err
|
|
}
|
|
return Want{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Want) Kind() uint8 { return t.o.Uint8(wantKindOff) }
|
|
func (t Want) Many() bool { return t.o.Bool(wantManyOff) }
|
|
|
|
// WantInput collects the field values for NewWant.
|
|
type WantInput struct {
|
|
Kind uint8
|
|
Many bool
|
|
}
|
|
|
|
// NewWant builds a ZAP-encoded Want message from in and returns the bytes.
|
|
func NewWant(in WantInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(wantSize)
|
|
ob.SetUint8(wantKindOff, in.Kind)
|
|
ob.SetBool(wantManyOff, in.Many)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
statsFpsOff = 0
|
|
statsQOff = 1
|
|
statsKbpsOff = 2
|
|
statsEncodeUsOff = 6
|
|
statsRttUsOff = 10
|
|
statsSize = 14
|
|
)
|
|
|
|
// Stats is a zero-copy view into a ZAP-encoded Stats message.
|
|
type Stats struct{ o zap.Object }
|
|
|
|
// WrapStats parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapStats(b []byte) (Stats, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Stats{}, err
|
|
}
|
|
return Stats{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Stats) Fps() uint8 { return t.o.Uint8(statsFpsOff) }
|
|
func (t Stats) Q() uint8 { return t.o.Uint8(statsQOff) }
|
|
func (t Stats) Kbps() uint32 { return t.o.Uint32(statsKbpsOff) }
|
|
func (t Stats) EncodeUs() uint32 { return t.o.Uint32(statsEncodeUsOff) }
|
|
func (t Stats) RttUs() uint32 { return t.o.Uint32(statsRttUsOff) }
|
|
|
|
// StatsInput collects the field values for NewStats.
|
|
type StatsInput struct {
|
|
Fps uint8
|
|
Q uint8
|
|
Kbps uint32
|
|
EncodeUs uint32
|
|
RttUs uint32
|
|
}
|
|
|
|
// NewStats builds a ZAP-encoded Stats message from in and returns the bytes.
|
|
func NewStats(in StatsInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(statsSize)
|
|
ob.SetUint8(statsFpsOff, in.Fps)
|
|
ob.SetUint8(statsQOff, in.Q)
|
|
ob.SetUint32(statsKbpsOff, in.Kbps)
|
|
ob.SetUint32(statsEncodeUsOff, in.EncodeUs)
|
|
ob.SetUint32(statsRttUsOff, in.RttUs)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
const (
|
|
byeCodeOff = 0
|
|
byeReasonOff = 2
|
|
byeSize = 10
|
|
)
|
|
|
|
// Bye is a zero-copy view into a ZAP-encoded Bye message.
|
|
type Bye struct{ o zap.Object }
|
|
|
|
// WrapBye parses b and returns a typed view. Returns an error if the
|
|
// wire-level checks (magic, version, size) fail.
|
|
func WrapBye(b []byte) (Bye, error) {
|
|
m, err := zap.Parse(b)
|
|
if err != nil {
|
|
return Bye{}, err
|
|
}
|
|
return Bye{o: m.Root()}, nil
|
|
}
|
|
|
|
func (t Bye) Code() uint16 { return t.o.Uint16(byeCodeOff) }
|
|
func (t Bye) Reason() string { return t.o.Text(byeReasonOff) }
|
|
|
|
// ByeInput collects the field values for NewBye.
|
|
type ByeInput struct {
|
|
Code uint16
|
|
Reason string
|
|
}
|
|
|
|
// NewBye builds a ZAP-encoded Bye message from in and returns the bytes.
|
|
func NewBye(in ByeInput) []byte {
|
|
b := zap.NewBuilder(256)
|
|
ob := b.StartObject(byeSize)
|
|
ob.SetUint16(byeCodeOff, in.Code)
|
|
ob.SetText(byeReasonOff, in.Reason)
|
|
ob.FinishAsRoot()
|
|
return b.Finish()
|
|
}
|
|
|
|
// Method ordinals for the Iris service (stable 1-based wire ids).
|
|
const (
|
|
IrisWatchOrdinal uint32 = 1
|
|
)
|
|
|
|
// IrisChannel ships one Call envelope and awaits its correlated Response.
|
|
type IrisChannel interface {
|
|
Call(envelope []byte) (rpc.Response, error)
|
|
}
|
|
|
|
// IrisClient is a typed RPC client for the Iris service over a ZAP call channel.
|
|
// Each call takes a fresh PromiseID from sess; the pipelined "On" form of a
|
|
// method sets Target to a prior call's Promise so the server chains them.
|
|
type IrisClient struct {
|
|
ch IrisChannel
|
|
cap []byte
|
|
sess *rpc.Session
|
|
}
|
|
|
|
// NewIrisClient returns a client that issues calls over ch, attaching cap
|
|
// (which may be nil) to every request.
|
|
func NewIrisClient(ch IrisChannel, capability []byte) *IrisClient {
|
|
return &IrisClient{ch: ch, cap: capability, sess: rpc.NewSession()}
|
|
}
|
|
|
|
func (c *IrisClient) Watch(req []byte) (rpc.Promise, error) {
|
|
return c.invokeWatch(rpc.NoTarget, req)
|
|
}
|
|
|
|
// WatchOn issues Watch as a dependent call pipelined on the answer of on:
|
|
// the server substitutes on's resolved result for this call's payload
|
|
// before dispatch, so it ships without waiting for on to round-trip.
|
|
func (c *IrisClient) WatchOn(on rpc.Promise) (rpc.Promise, error) {
|
|
return c.invokeWatch(on.ID, nil)
|
|
}
|
|
|
|
func (c *IrisClient) invokeWatch(target uint32, payload []byte) (rpc.Promise, error) {
|
|
p := c.sess.Next()
|
|
resp, err := c.ch.Call(rpc.BuildRequest(rpc.Call{
|
|
Method: IrisWatchOrdinal,
|
|
PromiseID: p.ID,
|
|
Target: target,
|
|
Cap: c.cap,
|
|
Payload: payload,
|
|
}))
|
|
if err != nil {
|
|
return p, err
|
|
}
|
|
if resp.Status != rpc.StatusOK {
|
|
return p, fmt.Errorf("Iris.Watch: status %d", resp.Status)
|
|
}
|
|
return p, nil
|
|
}
|
|
|
|
// IrisHandler is the server contract for the Iris service. Implement each
|
|
// method, then route requests to it with DispatchIris.
|
|
type IrisHandler interface {
|
|
Watch(req []byte) error
|
|
}
|
|
|
|
// DispatchIris decodes a Call envelope, routes it by method ordinal to h,
|
|
// and returns the response envelope. An unknown ordinal yields a
|
|
// StatusNotFound response; a handler error yields StatusInternal.
|
|
func DispatchIris(h IrisHandler, envelope []byte) ([]byte, error) {
|
|
call, err := rpc.ParseRequest(envelope)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
switch call.Method {
|
|
case IrisWatchOrdinal:
|
|
if err := h.Watch(call.Payload); err != nil {
|
|
return rpc.BuildResponse(rpc.StatusInternal, call.PromiseID, nil), nil
|
|
}
|
|
return rpc.BuildResponse(rpc.StatusOK, call.PromiseID, nil), nil
|
|
default:
|
|
return rpc.BuildResponse(rpc.StatusNotFound, call.PromiseID, nil), nil
|
|
}
|
|
}
|