#1 feat(xtgen): generator for xcb-proto bindings
A bigreq/replies_fuzz_test.go +21 -0
A bigreq/replies_generated.go +21 -0
A bigreq/requests_generated.go +21 -0
A bigreq/sizes_test.go +11 -0
A bigreq/types_generated.go +2 -0
A buf.go +92 -0
A buf_test.go +69 -0
A cmd/xtgen/emit.go +252 -0
A cmd/xtgen/expr.go +43 -0
A cmd/xtgen/ir.go +39 -0
A cmd/xtgen/layout.go +103 -0
M cmd/xtgen/main.go +47 -1
A cmd/xtgen/naming.go +43 -0
A cmd/xtgen/parse.go +292 -0
A cmd/xtgen/parse_test.go +74 -0
A cmd/xtgen/replies.go +554 -0
A cmd/xtgen/replies_test.go +70 -0
A cmd/xtgen/requests.go +359 -0
A cmd/xtgen/resolve.go +356 -0
A cmd/xtgen/resolve_test.go +165 -0
A cmd/xtgen/templates/ext.tmpl +10 -0
A cmd/xtgen/templates/replies.tmpl +5 -0
A cmd/xtgen/templates/requests.tmpl +5 -0
A cmd/xtgen/templates/sizes.tmpl +7 -0
A cmd/xtgen/templates/types.tmpl +5 -0
A cmd/xtgen/values.go +136 -0
A cmd/xtgen/values_test.go +93 -0
A composite/replies_fuzz_test.go +39 -0
A composite/replies_generated.go +42 -0
A composite/requests_generated.go +176 -0
A composite/sizes_test.go +14 -0
A composite/types_generated.go +7 -0
A ext.go +27 -0
A ext_generated.go +19 -0
A ge/replies_fuzz_test.go +22 -0
A ge/replies_generated.go +24 -0
A ge/requests_generated.go +24 -0
A ge/sizes_test.go +11 -0
A ge/types_generated.go +2 -0
A generate.go +3 -0
A internal/xtest/README.md +40 -0
A internal/xtest/capture_test.go +405 -0
A internal/xtest/golden.go +22 -0
A lists_test.go +87 -0
A render/replies_fuzz_test.go +135 -0
A render/replies_generated.go +380 -0
A render/requests_generated.go +1276 -0
A render/sizes_test.go +68 -0
A render/types_generated.go +522 -0
A replies_test.go +304 -0
A requests_test.go +62 -0
A res/replies_fuzz_test.go +146 -0
A res/replies_generated.go +348 -0
A res/requests_generated.go +144 -0
A res/sizes_test.go +47 -0
A res/types_generated.go +159 -0
A shape/replies_fuzz_test.go +86 -0
A shape/replies_generated.go +123 -0
A shape/requests_generated.go +214 -0
A shape/sizes_test.go +23 -0
A shape/types_generated.go +20 -0
A testdata/golden/render/CreatePicture.req.hex +3 -0
A testdata/golden/render/QueryPictFormats.reply.hex +3 -0
A testdata/golden/res/QueryClientIds.reply.hex +3 -0
A testdata/golden/res/QueryClientIds.req.hex +3 -0
A testdata/golden/xfixes/QueryVersion.reply.hex +3 -0
A testdata/golden/xfixes/QueryVersion.req.hex +3 -0
A testdata/golden/xproto/ChangeProperty.req.hex +3 -0
A testdata/golden/xproto/ChangeWindowAttributes.req.hex +3 -0
A testdata/golden/xproto/ConfigureWindow.req.hex +3 -0
A testdata/golden/xproto/ConfigureWindowAll.req.hex +3 -0
A testdata/golden/xproto/ConfigureWindowSparse.req.hex +3 -0
A testdata/golden/xproto/CreateWindow.req.hex +3 -0
A testdata/golden/xproto/GetGeometry.reply.hex +3 -0
A testdata/golden/xproto/GetGeometry.req.hex +3 -0
A testdata/golden/xproto/GetProperty.reply.hex +3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # source: Xvfb reply via raw socketpair tee to an independent reference request | |
| 2 | + | # xtrace fallback: local xtrace is glibc's execution tracer, not X11 xtrace | |
| 3 | + | 01080700010000001f000000000000000300000000000000000000000000000061626300 | |
A testdata/golden/xproto/GetPropertyEmpty.reply.hex +3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # source: Xvfb reply via raw socketpair tee to an independent reference request | |
| 2 | + | # xtrace fallback: local xtrace is glibc's execution tracer, not X11 xtrace | |
| 3 | + | 0100170000000000000000000000000000000000000000000000000000000000 | |
A testdata/golden/xproto/GetWindowAttributes.reply.hex +3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # source: Xvfb reply via raw socketpair tee to an independent reference request | |
| 2 | + | # xtrace fallback: local xtrace is glibc's execution tracer, not X11 xtrace | |
| 3 | + | 01001500030000002100000001000001ffffffff000000000101000020000000000000000000000000000000 | |
A testdata/golden/xproto/InternAtom.reply.hex +3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # source: Xvfb reply via raw socketpair tee to an independent reference request | |
| 2 | + | # xtrace fallback: local xtrace is glibc's execution tracer, not X11 xtrace | |
| 3 | + | 0100050000000000e70000000000000000000000000000000000000000000000 | |
A testdata/golden/xproto/InternAtom.req.hex +3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # source: Xvfb via raw socketpair tee; independent reference encoder; server accepted | |
| 2 | + | # xtrace fallback: local xtrace is glibc's execution tracer, not X11 xtrace | |
| 3 | + | 100004000700000058545552424f5f00 | |
A testdata/golden/xproto/ListExtensions.reply.hex +3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # source: Xvfb reply via raw socketpair tee to an independent reference request | |
| 2 | + | # xtrace fallback: local xtrace is glibc's execution tracer, not X11 xtrace | |
| 3 | + | 01171800370000000000000000000000000000000000000000000000000000001747656e65726963204576656e7420457874656e73696f6e055348415045074d49542d53484d0f58496e707574457874656e73696f6e0558544553540c4249472d52455155455354530453594e4309584b4559424f4152440758432d4d495343085345435552495459065846495845530652454e4445520552414e44520858494e4552414d4109436f6d706f736974650644414d414745104d49542d53435245454e2d53415645520d444f55424c452d425546464552065245434f52440750726573656e740a582d5265736f757263650658566964656f03474c5800 | |
A testdata/golden/xproto/MapWindow.req.hex +3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # source: Xvfb via raw socketpair tee; independent reference encoder; server accepted | |
| 2 | + | # xtrace fallback: local xtrace is glibc's execution tracer, not X11 xtrace | |
| 3 | + | 080002009f030000 | |
A testdata/golden/xproto/QueryExtension.reply.hex +3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # source: Xvfb reply via raw socketpair tee to an independent reference request | |
| 2 | + | # xtrace fallback: local xtrace is glibc's execution tracer, not X11 xtrace | |
| 3 | + | 0100010000000000018a578c0000000000000000000000000000000000000000 | |
A testdata/golden/xproto/QueryTree.reply.hex +3 -0
| @@ -0,0 +1,3 @@ | |||
| 1 | + | # source: Xvfb reply via raw socketpair tee to an independent reference request | |
| 2 | + | # xtrace fallback: local xtrace is glibc's execution tracer, not X11 xtrace | |
| 3 | + | 01001600020000009f03000000000000020000000000000000000000000000000200200001002000 | |
A values_test.go +103 -0
| @@ -0,0 +1,103 @@ | |||
| 1 | + | package xturbo_test | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "bytes" | |
| 5 | + | "encoding/binary" | |
| 6 | + | "testing" | |
| 7 | + | ||
| 8 | + | "bnema.dev/xturbo" | |
| 9 | + | "bnema.dev/xturbo/internal/xtest" | |
| 10 | + | "bnema.dev/xturbo/render" | |
| 11 | + | "bnema.dev/xturbo/xproto" | |
| 12 | + | ) | |
| 13 | + | ||
| 14 | + | func TestValueRequestGoldens(t *testing.T) { | |
| 15 | + | for _, name := range []string{"xproto/ConfigureWindow", "xproto/ConfigureWindowSparse", "xproto/ConfigureWindowAll", "xproto/CreateWindow", "xproto/ChangeWindowAttributes", "render/CreatePicture"} { | |
| 16 | + | t.Run(name, func(t *testing.T) { | |
| 17 | + | want, err := xtest.LoadHex("testdata/golden/" + name + ".req.hex") | |
| 18 | + | if err != nil { | |
| 19 | + | t.Fatal(err) | |
| 20 | + | } | |
| 21 | + | u32 := func(off int) uint32 { return binary.LittleEndian.Uint32(want[off:]) } | |
| 22 | + | b := xturbo.NewBuf(0) | |
| 23 | + | var seq xturbo.Seq | |
| 24 | + | switch name { | |
| 25 | + | case "xproto/ConfigureWindow": | |
| 26 | + | seq = xproto.ConfigureWindow(b, xproto.Window(u32(4)), &xproto.ConfigureWindowValues{}) | |
| 27 | + | case "xproto/ConfigureWindowSparse": | |
| 28 | + | var v xproto.ConfigureWindowValues | |
| 29 | + | if v.SetStackMode(xproto.StackModeAbove).SetWidth(80).SetX(-7) != &v { | |
| 30 | + | t.Fatal("setter chaining") | |
| 31 | + | } | |
| 32 | + | seq = xproto.ConfigureWindow(b, xproto.Window(u32(4)), &v) | |
| 33 | + | case "xproto/ConfigureWindowAll": | |
| 34 | + | var v xproto.ConfigureWindowValues | |
| 35 | + | v.SetStackMode(xproto.StackModeAbove).SetSibling(xproto.Window(u32(32))).SetBorderWidth(2).SetHeight(72).SetWidth(96).SetY(9).SetX(-3) | |
| 36 | + | seq = xproto.ConfigureWindow(b, xproto.Window(u32(4)), &v) | |
| 37 | + | case "xproto/CreateWindow": | |
| 38 | + | var v xproto.CreateWindowValues | |
| 39 | + | v.SetSaveUnder(false).SetOverrideRedirect(true).SetBackgroundPixel(0x123456) | |
| 40 | + | seq = xproto.CreateWindow(b, 0, xproto.Window(u32(4)), xproto.Window(u32(8)), 0, 0, 64, 48, 0, xproto.WindowClassInputOutput, 0, &v) | |
| 41 | + | case "xproto/ChangeWindowAttributes": | |
| 42 | + | var v xproto.ChangeWindowAttributesValues | |
| 43 | + | v.SetSaveUnder(true).SetOverrideRedirect(false) | |
| 44 | + | seq = xproto.ChangeWindowAttributes(b, xproto.Window(u32(4)), &v) | |
| 45 | + | case "render/CreatePicture": | |
| 46 | + | var ext xturbo.ExtTable | |
| 47 | + | ext.Set(xturbo.ExtRender, want[0], 0, 0) | |
| 48 | + | b.Ext = &ext | |
| 49 | + | var v render.CreatePictureValues | |
| 50 | + | v.SetClipyorigin(7).SetClipxorigin(-5).SetRepeat(render.RepeatNormal) | |
| 51 | + | seq = render.CreatePicture(b, render.Picture(u32(4)), xproto.Drawable(u32(8)), render.Pictformat(u32(12)), &v) | |
| 52 | + | } | |
| 53 | + | if seq != 1 || b.Err() != nil { | |
| 54 | + | t.Fatalf("seq=%d err=%v", seq, b.Err()) | |
| 55 | + | } | |
| 56 | + | if !bytes.Equal(b.Bytes(), want) { | |
| 57 | + | t.Fatalf("got %x want %x", b.Bytes(), want) | |
| 58 | + | } | |
| 59 | + | }) | |
| 60 | + | } | |
| 61 | + | } | |
| 62 | + | ||
| 63 | + | func TestAllocValueRequests(t *testing.T) { | |
| 64 | + | b := xturbo.NewBuf(0) | |
| 65 | + | var ext xturbo.ExtTable | |
| 66 | + | ext.Set(xturbo.ExtRender, 139, 0, 0) | |
| 67 | + | b.Ext = &ext | |
| 68 | + | var v xproto.ConfigureWindowValues | |
| 69 | + | v.SetX(-1).SetY(-2).SetWidth(800).SetHeight(600).SetBorderWidth(1).SetSibling(2).SetStackMode(xproto.StackModeAbove) | |
| 70 | + | var create xproto.CreateWindowValues | |
| 71 | + | create.SetOverrideRedirect(true).SetSaveUnder(false) | |
| 72 | + | var change xproto.ChangeWindowAttributesValues | |
| 73 | + | change.SetOverrideRedirect(false).SetSaveUnder(true) | |
| 74 | + | var pic render.CreatePictureValues | |
| 75 | + | pic.SetRepeat(render.RepeatNormal).SetClipxorigin(-1) | |
| 76 | + | if n := testing.AllocsPerRun(1000, func() { | |
| 77 | + | b.Reset() | |
| 78 | + | xproto.ConfigureWindow(b, 1, &v) | |
| 79 | + | xproto.CreateWindow(b, 0, 1, 2, 0, 0, 80, 60, 0, xproto.WindowClassInputOutput, 0, &create) | |
| 80 | + | xproto.ChangeWindowAttributes(b, 1, &change) | |
| 81 | + | render.CreatePicture(b, 1, 1, 1, &pic) | |
| 82 | + | }); n != 0 { | |
| 83 | + | t.Fatal(n) | |
| 84 | + | } | |
| 85 | + | if b.Err() != nil { | |
| 86 | + | t.Fatal(b.Err()) | |
| 87 | + | } | |
| 88 | + | } | |
| 89 | + | ||
| 90 | + | func TestValueRequestFailures(t *testing.T) { | |
| 91 | + | b := xturbo.NewBuf(0) | |
| 92 | + | b.Fail(xturbo.ErrBadLength) | |
| 93 | + | if xproto.ConfigureWindow(b, 1, &xproto.ConfigureWindowValues{}) != 0 || b.Len() != 0 || b.Err() != xturbo.ErrBadLength { | |
| 94 | + | t.Fatal("sticky error") | |
| 95 | + | } | |
| 96 | + | for _, ext := range []*xturbo.ExtTable{nil, {}} { | |
| 97 | + | b := xturbo.NewBuf(0) | |
| 98 | + | b.Ext = ext | |
| 99 | + | if render.CreatePicture(b, 1, 1, 1, &render.CreatePictureValues{}) != 0 || b.Err() != xturbo.ErrExtMissing || b.Len() != 0 { | |
| 100 | + | t.Fatal("missing extension") | |
| 101 | + | } | |
| 102 | + | } | |
| 103 | + | } | |
A xcmisc/replies_fuzz_test.go +60 -0
| @@ -0,0 +1,60 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xcmisc | |
| 3 | + | ||
| 4 | + | import "testing" | |
| 5 | + | ||
| 6 | + | func FuzzParseGetVersionReply(f *testing.F) { | |
| 7 | + | f.Add(make([]byte, 32)) | |
| 8 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 9 | + | r, ok := ParseGetVersionReply(raw) | |
| 10 | + | if !ok { | |
| 11 | + | if len(raw) >= 32 { | |
| 12 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 13 | + | } | |
| 14 | + | return | |
| 15 | + | } | |
| 16 | + | if len(r.Raw()) != len(raw) { | |
| 17 | + | t.Fatal("Raw must return the parsed bytes") | |
| 18 | + | } | |
| 19 | + | _ = r.ServerMajorVersion() | |
| 20 | + | _ = r.ServerMinorVersion() | |
| 21 | + | }) | |
| 22 | + | } | |
| 23 | + | ||
| 24 | + | func FuzzParseGetXIDRangeReply(f *testing.F) { | |
| 25 | + | f.Add(make([]byte, 32)) | |
| 26 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 27 | + | r, ok := ParseGetXIDRangeReply(raw) | |
| 28 | + | if !ok { | |
| 29 | + | if len(raw) >= 32 { | |
| 30 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 31 | + | } | |
| 32 | + | return | |
| 33 | + | } | |
| 34 | + | if len(r.Raw()) != len(raw) { | |
| 35 | + | t.Fatal("Raw must return the parsed bytes") | |
| 36 | + | } | |
| 37 | + | _ = r.StartId() | |
| 38 | + | _ = r.Count() | |
| 39 | + | }) | |
| 40 | + | } | |
| 41 | + | ||
| 42 | + | func FuzzParseGetXIDListReply(f *testing.F) { | |
| 43 | + | f.Add(make([]byte, 32)) | |
| 44 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 45 | + | r, ok := ParseGetXIDListReply(raw) | |
| 46 | + | if !ok { | |
| 47 | + | return | |
| 48 | + | } | |
| 49 | + | if len(r.Raw()) != len(raw) { | |
| 50 | + | t.Fatal("Raw must return the parsed bytes") | |
| 51 | + | } | |
| 52 | + | _ = r.IdsLen() | |
| 53 | + | { | |
| 54 | + | l0 := r.Ids() | |
| 55 | + | for i := 0; i < l0.Len(); i++ { | |
| 56 | + | _ = l0.At(i) | |
| 57 | + | } | |
| 58 | + | } | |
| 59 | + | }) | |
| 60 | + | } | |
A xcmisc/replies_generated.go +80 -0
| @@ -0,0 +1,80 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xcmisc | |
| 3 | + | ||
| 4 | + | import "encoding/binary" | |
| 5 | + | ||
| 6 | + | // GetVersionReply is a zero-copy view over a GetVersion reply; offsets count from reply byte 0. | |
| 7 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 8 | + | type GetVersionReply struct{ raw []byte } | |
| 9 | + | ||
| 10 | + | // ParseGetVersionReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 11 | + | func ParseGetVersionReply(raw []byte) (GetVersionReply, bool) { | |
| 12 | + | if len(raw) < 32 { | |
| 13 | + | return GetVersionReply{}, false | |
| 14 | + | } | |
| 15 | + | r := GetVersionReply{raw: raw} | |
| 16 | + | return r, true | |
| 17 | + | } | |
| 18 | + | func (r GetVersionReply) Raw() []byte { return r.raw } | |
| 19 | + | func (r GetVersionReply) ServerMajorVersion() uint16 { | |
| 20 | + | return uint16(binary.LittleEndian.Uint16(r.raw[8:])) | |
| 21 | + | } | |
| 22 | + | func (r GetVersionReply) ServerMinorVersion() uint16 { | |
| 23 | + | return uint16(binary.LittleEndian.Uint16(r.raw[10:])) | |
| 24 | + | } | |
| 25 | + | ||
| 26 | + | // GetXIDRangeReply is a zero-copy view over a GetXIDRange reply; offsets count from reply byte 0. | |
| 27 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 28 | + | type GetXIDRangeReply struct{ raw []byte } | |
| 29 | + | ||
| 30 | + | // ParseGetXIDRangeReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 31 | + | func ParseGetXIDRangeReply(raw []byte) (GetXIDRangeReply, bool) { | |
| 32 | + | if len(raw) < 32 { | |
| 33 | + | return GetXIDRangeReply{}, false | |
| 34 | + | } | |
| 35 | + | r := GetXIDRangeReply{raw: raw} | |
| 36 | + | return r, true | |
| 37 | + | } | |
| 38 | + | func (r GetXIDRangeReply) Raw() []byte { return r.raw } | |
| 39 | + | func (r GetXIDRangeReply) StartId() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 40 | + | func (r GetXIDRangeReply) Count() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[12:])) } | |
| 41 | + | ||
| 42 | + | // GetXIDListReply is a zero-copy view over a GetXIDList reply; offsets count from reply byte 0. | |
| 43 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 44 | + | type GetXIDListReply struct{ raw []byte } | |
| 45 | + | ||
| 46 | + | // ParseGetXIDListReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 47 | + | func ParseGetXIDListReply(raw []byte) (GetXIDListReply, bool) { | |
| 48 | + | if len(raw) < 32 { | |
| 49 | + | return GetXIDListReply{}, false | |
| 50 | + | } | |
| 51 | + | r := GetXIDListReply{raw: raw} | |
| 52 | + | off := 32 | |
| 53 | + | { | |
| 54 | + | n := int(r.IdsLen()) | |
| 55 | + | if n < 0 || n > len(r.raw) { | |
| 56 | + | return GetXIDListReply{}, false | |
| 57 | + | } | |
| 58 | + | off += n * 4 | |
| 59 | + | } | |
| 60 | + | if off > len(r.raw) { | |
| 61 | + | return GetXIDListReply{}, false | |
| 62 | + | } | |
| 63 | + | if off > len(r.raw) { | |
| 64 | + | return GetXIDListReply{}, false | |
| 65 | + | } | |
| 66 | + | return r, true | |
| 67 | + | } | |
| 68 | + | func (r GetXIDListReply) Raw() []byte { return r.raw } | |
| 69 | + | func (r GetXIDListReply) IdsLen() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 70 | + | func (r GetXIDListReply) Ids() Uint32List { | |
| 71 | + | off := 32 | |
| 72 | + | end := off + (int(r.IdsLen()))*4 | |
| 73 | + | return Uint32List{b: r.raw[off:end:end]} | |
| 74 | + | } | |
| 75 | + | ||
| 76 | + | // Uint32List is a borrowed view over a wire list of uint32. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 77 | + | type Uint32List struct{ b []byte } | |
| 78 | + | ||
| 79 | + | func (l Uint32List) Len() int { return len(l.b) / 4 } | |
| 80 | + | func (l Uint32List) At(i int) uint32 { return uint32(binary.LittleEndian.Uint32(l.b[i*4:])) } | |
A xcmisc/requests_generated.go +59 -0
| @@ -0,0 +1,59 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xcmisc | |
| 3 | + | ||
| 4 | + | import "encoding/binary" | |
| 5 | + | import "bnema.dev/xturbo" | |
| 6 | + | ||
| 7 | + | func GetVersion(b *xturbo.Buf, clientMajorVersion uint16, clientMinorVersion uint16) xturbo.Seq { | |
| 8 | + | if b.Ext == nil { | |
| 9 | + | b.Fail(xturbo.ErrExtMissing) | |
| 10 | + | return 0 | |
| 11 | + | } | |
| 12 | + | major := b.Ext.Major(xturbo.ExtXCMisc) | |
| 13 | + | if major == 0 { | |
| 14 | + | b.Fail(xturbo.ErrExtMissing) | |
| 15 | + | return 0 | |
| 16 | + | } | |
| 17 | + | p, seq := b.Request(major, 0, 4) | |
| 18 | + | if p == nil { | |
| 19 | + | return 0 | |
| 20 | + | } | |
| 21 | + | binary.LittleEndian.PutUint16(p[0:], uint16(clientMajorVersion)) | |
| 22 | + | binary.LittleEndian.PutUint16(p[2:], uint16(clientMinorVersion)) | |
| 23 | + | return seq | |
| 24 | + | } | |
| 25 | + | ||
| 26 | + | func GetXIDRange(b *xturbo.Buf) xturbo.Seq { | |
| 27 | + | if b.Ext == nil { | |
| 28 | + | b.Fail(xturbo.ErrExtMissing) | |
| 29 | + | return 0 | |
| 30 | + | } | |
| 31 | + | major := b.Ext.Major(xturbo.ExtXCMisc) | |
| 32 | + | if major == 0 { | |
| 33 | + | b.Fail(xturbo.ErrExtMissing) | |
| 34 | + | return 0 | |
| 35 | + | } | |
| 36 | + | p, seq := b.Request(major, 1, 0) | |
| 37 | + | if p == nil { | |
| 38 | + | return 0 | |
| 39 | + | } | |
| 40 | + | return seq | |
| 41 | + | } | |
| 42 | + | ||
| 43 | + | func GetXIDList(b *xturbo.Buf, count uint32) xturbo.Seq { | |
| 44 | + | if b.Ext == nil { | |
| 45 | + | b.Fail(xturbo.ErrExtMissing) | |
| 46 | + | return 0 | |
| 47 | + | } | |
| 48 | + | major := b.Ext.Major(xturbo.ExtXCMisc) | |
| 49 | + | if major == 0 { | |
| 50 | + | b.Fail(xturbo.ErrExtMissing) | |
| 51 | + | return 0 | |
| 52 | + | } | |
| 53 | + | p, seq := b.Request(major, 2, 4) | |
| 54 | + | if p == nil { | |
| 55 | + | return 0 | |
| 56 | + | } | |
| 57 | + | binary.LittleEndian.PutUint32(p[0:], uint32(count)) | |
| 58 | + | return seq | |
| 59 | + | } | |
A xcmisc/sizes_test.go +17 -0
| @@ -0,0 +1,17 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xcmisc | |
| 3 | + | ||
| 4 | + | import "testing" | |
| 5 | + | ||
| 6 | + | func TestWireSizes(t *testing.T) { | |
| 7 | + | if got := 32; got != 32 { | |
| 8 | + | t.Errorf("reply GetVersion fixed size = %d", got) | |
| 9 | + | } | |
| 10 | + | if got := 32; got != 32 { | |
| 11 | + | t.Errorf("reply GetXIDRange fixed size = %d", got) | |
| 12 | + | } | |
| 13 | + | if got := 32; got != 32 { | |
| 14 | + | t.Errorf("reply GetXIDList fixed size = %d", got) | |
| 15 | + | } | |
| 16 | + | ||
| 17 | + | } | |
A xcmisc/types_generated.go +2 -0
| @@ -0,0 +1,2 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xcmisc | |
A xfixes/replies_fuzz_test.go +136 -0
| @@ -0,0 +1,136 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xfixes | |
| 3 | + | ||
| 4 | + | import "testing" | |
| 5 | + | import "bnema.dev/xturbo/internal/xtest" | |
| 6 | + | ||
| 7 | + | func FuzzParseQueryVersionReply(f *testing.F) { | |
| 8 | + | f.Add(make([]byte, 32)) | |
| 9 | + | if raw, err := xtest.LoadHex("../testdata/golden/xfixes/QueryVersion.reply.hex"); err != nil { | |
| 10 | + | f.Fatal(err) | |
| 11 | + | } else { | |
| 12 | + | f.Add(raw) | |
| 13 | + | } | |
| 14 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 15 | + | r, ok := ParseQueryVersionReply(raw) | |
| 16 | + | if !ok { | |
| 17 | + | if len(raw) >= 32 { | |
| 18 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 19 | + | } | |
| 20 | + | return | |
| 21 | + | } | |
| 22 | + | if len(r.Raw()) != len(raw) { | |
| 23 | + | t.Fatal("Raw must return the parsed bytes") | |
| 24 | + | } | |
| 25 | + | _ = r.MajorVersion() | |
| 26 | + | _ = r.MinorVersion() | |
| 27 | + | }) | |
| 28 | + | } | |
| 29 | + | ||
| 30 | + | func FuzzParseGetCursorImageReply(f *testing.F) { | |
| 31 | + | f.Add(make([]byte, 32)) | |
| 32 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 33 | + | r, ok := ParseGetCursorImageReply(raw) | |
| 34 | + | if !ok { | |
| 35 | + | return | |
| 36 | + | } | |
| 37 | + | if len(r.Raw()) != len(raw) { | |
| 38 | + | t.Fatal("Raw must return the parsed bytes") | |
| 39 | + | } | |
| 40 | + | _ = r.X() | |
| 41 | + | _ = r.Y() | |
| 42 | + | _ = r.Width() | |
| 43 | + | _ = r.Height() | |
| 44 | + | _ = r.Xhot() | |
| 45 | + | _ = r.Yhot() | |
| 46 | + | _ = r.CursorSerial() | |
| 47 | + | { | |
| 48 | + | l0 := r.CursorImage() | |
| 49 | + | for i := 0; i < l0.Len(); i++ { | |
| 50 | + | _ = l0.At(i) | |
| 51 | + | } | |
| 52 | + | } | |
| 53 | + | }) | |
| 54 | + | } | |
| 55 | + | ||
| 56 | + | func FuzzParseFetchRegionReply(f *testing.F) { | |
| 57 | + | f.Add(make([]byte, 32)) | |
| 58 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 59 | + | r, ok := ParseFetchRegionReply(raw) | |
| 60 | + | if !ok { | |
| 61 | + | return | |
| 62 | + | } | |
| 63 | + | if len(r.Raw()) != len(raw) { | |
| 64 | + | t.Fatal("Raw must return the parsed bytes") | |
| 65 | + | } | |
| 66 | + | _ = r.Extents() | |
| 67 | + | { | |
| 68 | + | l0 := r.Rectangles() | |
| 69 | + | for i := 0; i < l0.Len(); i++ { | |
| 70 | + | _ = l0.At(i) | |
| 71 | + | } | |
| 72 | + | } | |
| 73 | + | }) | |
| 74 | + | } | |
| 75 | + | ||
| 76 | + | func FuzzParseGetCursorNameReply(f *testing.F) { | |
| 77 | + | f.Add(make([]byte, 32)) | |
| 78 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 79 | + | r, ok := ParseGetCursorNameReply(raw) | |
| 80 | + | if !ok { | |
| 81 | + | return | |
| 82 | + | } | |
| 83 | + | if len(r.Raw()) != len(raw) { | |
| 84 | + | t.Fatal("Raw must return the parsed bytes") | |
| 85 | + | } | |
| 86 | + | _ = r.Atom() | |
| 87 | + | _ = r.Nbytes() | |
| 88 | + | _ = len(r.Name()) | |
| 89 | + | }) | |
| 90 | + | } | |
| 91 | + | ||
| 92 | + | func FuzzParseGetCursorImageAndNameReply(f *testing.F) { | |
| 93 | + | f.Add(make([]byte, 32)) | |
| 94 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 95 | + | r, ok := ParseGetCursorImageAndNameReply(raw) | |
| 96 | + | if !ok { | |
| 97 | + | return | |
| 98 | + | } | |
| 99 | + | if len(r.Raw()) != len(raw) { | |
| 100 | + | t.Fatal("Raw must return the parsed bytes") | |
| 101 | + | } | |
| 102 | + | _ = r.X() | |
| 103 | + | _ = r.Y() | |
| 104 | + | _ = r.Width() | |
| 105 | + | _ = r.Height() | |
| 106 | + | _ = r.Xhot() | |
| 107 | + | _ = r.Yhot() | |
| 108 | + | _ = r.CursorSerial() | |
| 109 | + | _ = r.CursorAtom() | |
| 110 | + | _ = r.Nbytes() | |
| 111 | + | { | |
| 112 | + | l0 := r.CursorImage() | |
| 113 | + | for i := 0; i < l0.Len(); i++ { | |
| 114 | + | _ = l0.At(i) | |
| 115 | + | } | |
| 116 | + | } | |
| 117 | + | _ = len(r.Name()) | |
| 118 | + | }) | |
| 119 | + | } | |
| 120 | + | ||
| 121 | + | func FuzzParseGetClientDisconnectModeReply(f *testing.F) { | |
| 122 | + | f.Add(make([]byte, 32)) | |
| 123 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 124 | + | r, ok := ParseGetClientDisconnectModeReply(raw) | |
| 125 | + | if !ok { | |
| 126 | + | if len(raw) >= 32 { | |
| 127 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 128 | + | } | |
| 129 | + | return | |
| 130 | + | } | |
| 131 | + | if len(r.Raw()) != len(raw) { | |
| 132 | + | t.Fatal("Raw must return the parsed bytes") | |
| 133 | + | } | |
| 134 | + | _ = r.DisconnectMode() | |
| 135 | + | }) | |
| 136 | + | } | |
A xfixes/replies_generated.go +242 -0
| @@ -0,0 +1,242 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xfixes | |
| 3 | + | ||
| 4 | + | import "bnema.dev/xturbo/xproto" | |
| 5 | + | import "encoding/binary" | |
| 6 | + | ||
| 7 | + | // QueryVersionReply is a zero-copy view over a QueryVersion reply; offsets count from reply byte 0. | |
| 8 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 9 | + | type QueryVersionReply struct{ raw []byte } | |
| 10 | + | ||
| 11 | + | // ParseQueryVersionReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 12 | + | func ParseQueryVersionReply(raw []byte) (QueryVersionReply, bool) { | |
| 13 | + | if len(raw) < 32 { | |
| 14 | + | return QueryVersionReply{}, false | |
| 15 | + | } | |
| 16 | + | r := QueryVersionReply{raw: raw} | |
| 17 | + | return r, true | |
| 18 | + | } | |
| 19 | + | func (r QueryVersionReply) Raw() []byte { return r.raw } | |
| 20 | + | func (r QueryVersionReply) MajorVersion() uint32 { | |
| 21 | + | return uint32(binary.LittleEndian.Uint32(r.raw[8:])) | |
| 22 | + | } | |
| 23 | + | func (r QueryVersionReply) MinorVersion() uint32 { | |
| 24 | + | return uint32(binary.LittleEndian.Uint32(r.raw[12:])) | |
| 25 | + | } | |
| 26 | + | ||
| 27 | + | // GetCursorImageReply is a zero-copy view over a GetCursorImage reply; offsets count from reply byte 0. | |
| 28 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 29 | + | type GetCursorImageReply struct{ raw []byte } | |
| 30 | + | ||
| 31 | + | // ParseGetCursorImageReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 32 | + | func ParseGetCursorImageReply(raw []byte) (GetCursorImageReply, bool) { | |
| 33 | + | if len(raw) < 32 { | |
| 34 | + | return GetCursorImageReply{}, false | |
| 35 | + | } | |
| 36 | + | r := GetCursorImageReply{raw: raw} | |
| 37 | + | off := 32 | |
| 38 | + | { | |
| 39 | + | n := (int(r.Width()) * int(r.Height())) | |
| 40 | + | if n < 0 || n > len(r.raw) { | |
| 41 | + | return GetCursorImageReply{}, false | |
| 42 | + | } | |
| 43 | + | off += n * 4 | |
| 44 | + | } | |
| 45 | + | if off > len(r.raw) { | |
| 46 | + | return GetCursorImageReply{}, false | |
| 47 | + | } | |
| 48 | + | if off > len(r.raw) { | |
| 49 | + | return GetCursorImageReply{}, false | |
| 50 | + | } | |
| 51 | + | return r, true | |
| 52 | + | } | |
| 53 | + | func (r GetCursorImageReply) Raw() []byte { return r.raw } | |
| 54 | + | func (r GetCursorImageReply) X() int16 { return int16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 55 | + | func (r GetCursorImageReply) Y() int16 { return int16(binary.LittleEndian.Uint16(r.raw[10:])) } | |
| 56 | + | func (r GetCursorImageReply) Width() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[12:])) } | |
| 57 | + | func (r GetCursorImageReply) Height() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[14:])) } | |
| 58 | + | func (r GetCursorImageReply) Xhot() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[16:])) } | |
| 59 | + | func (r GetCursorImageReply) Yhot() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[18:])) } | |
| 60 | + | func (r GetCursorImageReply) CursorSerial() uint32 { | |
| 61 | + | return uint32(binary.LittleEndian.Uint32(r.raw[20:])) | |
| 62 | + | } | |
| 63 | + | func (r GetCursorImageReply) CursorImage() Uint32List { | |
| 64 | + | off := 32 | |
| 65 | + | end := off + (int(r.Width())*int(r.Height()))*4 | |
| 66 | + | return Uint32List{b: r.raw[off:end:end]} | |
| 67 | + | } | |
| 68 | + | ||
| 69 | + | // FetchRegionReply is a zero-copy view over a FetchRegion reply; offsets count from reply byte 0. | |
| 70 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 71 | + | type FetchRegionReply struct{ raw []byte } | |
| 72 | + | ||
| 73 | + | // ParseFetchRegionReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 74 | + | func ParseFetchRegionReply(raw []byte) (FetchRegionReply, bool) { | |
| 75 | + | if len(raw) < 32 { | |
| 76 | + | return FetchRegionReply{}, false | |
| 77 | + | } | |
| 78 | + | r := FetchRegionReply{raw: raw} | |
| 79 | + | off := 32 | |
| 80 | + | { | |
| 81 | + | n := (int(binary.LittleEndian.Uint32(r.raw[4:])) / 2) | |
| 82 | + | if n < 0 || n > len(r.raw) { | |
| 83 | + | return FetchRegionReply{}, false | |
| 84 | + | } | |
| 85 | + | off += n * 8 | |
| 86 | + | } | |
| 87 | + | if off > len(r.raw) { | |
| 88 | + | return FetchRegionReply{}, false | |
| 89 | + | } | |
| 90 | + | if off > len(r.raw) { | |
| 91 | + | return FetchRegionReply{}, false | |
| 92 | + | } | |
| 93 | + | return r, true | |
| 94 | + | } | |
| 95 | + | func (r FetchRegionReply) Raw() []byte { return r.raw } | |
| 96 | + | func (r FetchRegionReply) Extents() xproto.Rectangle { return xproto.GetRectangle(r.raw[8:]) } | |
| 97 | + | func (r FetchRegionReply) Rectangles() RectangleList { | |
| 98 | + | off := 32 | |
| 99 | + | end := off + (int(binary.LittleEndian.Uint32(r.raw[4:]))/2)*8 | |
| 100 | + | return RectangleList{b: r.raw[off:end:end]} | |
| 101 | + | } | |
| 102 | + | ||
| 103 | + | // GetCursorNameReply is a zero-copy view over a GetCursorName reply; offsets count from reply byte 0. | |
| 104 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 105 | + | type GetCursorNameReply struct{ raw []byte } | |
| 106 | + | ||
| 107 | + | // ParseGetCursorNameReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 108 | + | func ParseGetCursorNameReply(raw []byte) (GetCursorNameReply, bool) { | |
| 109 | + | if len(raw) < 32 { | |
| 110 | + | return GetCursorNameReply{}, false | |
| 111 | + | } | |
| 112 | + | r := GetCursorNameReply{raw: raw} | |
| 113 | + | off := 32 | |
| 114 | + | { | |
| 115 | + | n := int(r.Nbytes()) | |
| 116 | + | if n < 0 || n > len(r.raw) { | |
| 117 | + | return GetCursorNameReply{}, false | |
| 118 | + | } | |
| 119 | + | off += n * 1 | |
| 120 | + | } | |
| 121 | + | if off > len(r.raw) { | |
| 122 | + | return GetCursorNameReply{}, false | |
| 123 | + | } | |
| 124 | + | if off > len(r.raw) { | |
| 125 | + | return GetCursorNameReply{}, false | |
| 126 | + | } | |
| 127 | + | return r, true | |
| 128 | + | } | |
| 129 | + | func (r GetCursorNameReply) Raw() []byte { return r.raw } | |
| 130 | + | func (r GetCursorNameReply) Atom() xproto.Atom { | |
| 131 | + | return xproto.Atom(binary.LittleEndian.Uint32(r.raw[8:])) | |
| 132 | + | } | |
| 133 | + | func (r GetCursorNameReply) Nbytes() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[12:])) } | |
| 134 | + | func (r GetCursorNameReply) Name() []byte { | |
| 135 | + | off := 32 | |
| 136 | + | end := off + int(r.Nbytes()) | |
| 137 | + | return r.raw[off:end:end] | |
| 138 | + | } | |
| 139 | + | ||
| 140 | + | // GetCursorImageAndNameReply is a zero-copy view over a GetCursorImageAndName reply; offsets count from reply byte 0. | |
| 141 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 142 | + | type GetCursorImageAndNameReply struct{ raw []byte } | |
| 143 | + | ||
| 144 | + | // ParseGetCursorImageAndNameReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 145 | + | func ParseGetCursorImageAndNameReply(raw []byte) (GetCursorImageAndNameReply, bool) { | |
| 146 | + | if len(raw) < 32 { | |
| 147 | + | return GetCursorImageAndNameReply{}, false | |
| 148 | + | } | |
| 149 | + | r := GetCursorImageAndNameReply{raw: raw} | |
| 150 | + | off := 32 | |
| 151 | + | { | |
| 152 | + | n := (int(r.Width()) * int(r.Height())) | |
| 153 | + | if n < 0 || n > len(r.raw) { | |
| 154 | + | return GetCursorImageAndNameReply{}, false | |
| 155 | + | } | |
| 156 | + | off += n * 4 | |
| 157 | + | } | |
| 158 | + | if off > len(r.raw) { | |
| 159 | + | return GetCursorImageAndNameReply{}, false | |
| 160 | + | } | |
| 161 | + | { | |
| 162 | + | n := int(r.Nbytes()) | |
| 163 | + | if n < 0 || n > len(r.raw) { | |
| 164 | + | return GetCursorImageAndNameReply{}, false | |
| 165 | + | } | |
| 166 | + | off += n * 1 | |
| 167 | + | } | |
| 168 | + | if off > len(r.raw) { | |
| 169 | + | return GetCursorImageAndNameReply{}, false | |
| 170 | + | } | |
| 171 | + | if off > len(r.raw) { | |
| 172 | + | return GetCursorImageAndNameReply{}, false | |
| 173 | + | } | |
| 174 | + | return r, true | |
| 175 | + | } | |
| 176 | + | func (r GetCursorImageAndNameReply) Raw() []byte { return r.raw } | |
| 177 | + | func (r GetCursorImageAndNameReply) X() int16 { return int16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 178 | + | func (r GetCursorImageAndNameReply) Y() int16 { return int16(binary.LittleEndian.Uint16(r.raw[10:])) } | |
| 179 | + | func (r GetCursorImageAndNameReply) Width() uint16 { | |
| 180 | + | return uint16(binary.LittleEndian.Uint16(r.raw[12:])) | |
| 181 | + | } | |
| 182 | + | func (r GetCursorImageAndNameReply) Height() uint16 { | |
| 183 | + | return uint16(binary.LittleEndian.Uint16(r.raw[14:])) | |
| 184 | + | } | |
| 185 | + | func (r GetCursorImageAndNameReply) Xhot() uint16 { | |
| 186 | + | return uint16(binary.LittleEndian.Uint16(r.raw[16:])) | |
| 187 | + | } | |
| 188 | + | func (r GetCursorImageAndNameReply) Yhot() uint16 { | |
| 189 | + | return uint16(binary.LittleEndian.Uint16(r.raw[18:])) | |
| 190 | + | } | |
| 191 | + | func (r GetCursorImageAndNameReply) CursorSerial() uint32 { | |
| 192 | + | return uint32(binary.LittleEndian.Uint32(r.raw[20:])) | |
| 193 | + | } | |
| 194 | + | func (r GetCursorImageAndNameReply) CursorAtom() xproto.Atom { | |
| 195 | + | return xproto.Atom(binary.LittleEndian.Uint32(r.raw[24:])) | |
| 196 | + | } | |
| 197 | + | func (r GetCursorImageAndNameReply) Nbytes() uint16 { | |
| 198 | + | return uint16(binary.LittleEndian.Uint16(r.raw[28:])) | |
| 199 | + | } | |
| 200 | + | func (r GetCursorImageAndNameReply) CursorImage() Uint32List { | |
| 201 | + | off := 32 | |
| 202 | + | end := off + (int(r.Width())*int(r.Height()))*4 | |
| 203 | + | return Uint32List{b: r.raw[off:end:end]} | |
| 204 | + | } | |
| 205 | + | func (r GetCursorImageAndNameReply) Name() []byte { | |
| 206 | + | off := 32 | |
| 207 | + | { | |
| 208 | + | n := (int(r.Width()) * int(r.Height())) | |
| 209 | + | off += n * 4 | |
| 210 | + | } | |
| 211 | + | end := off + int(r.Nbytes()) | |
| 212 | + | return r.raw[off:end:end] | |
| 213 | + | } | |
| 214 | + | ||
| 215 | + | // GetClientDisconnectModeReply is a zero-copy view over a GetClientDisconnectMode reply; offsets count from reply byte 0. | |
| 216 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 217 | + | type GetClientDisconnectModeReply struct{ raw []byte } | |
| 218 | + | ||
| 219 | + | // ParseGetClientDisconnectModeReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 220 | + | func ParseGetClientDisconnectModeReply(raw []byte) (GetClientDisconnectModeReply, bool) { | |
| 221 | + | if len(raw) < 32 { | |
| 222 | + | return GetClientDisconnectModeReply{}, false | |
| 223 | + | } | |
| 224 | + | r := GetClientDisconnectModeReply{raw: raw} | |
| 225 | + | return r, true | |
| 226 | + | } | |
| 227 | + | func (r GetClientDisconnectModeReply) Raw() []byte { return r.raw } | |
| 228 | + | func (r GetClientDisconnectModeReply) DisconnectMode() ClientDisconnectFlags { | |
| 229 | + | return ClientDisconnectFlags(binary.LittleEndian.Uint32(r.raw[8:])) | |
| 230 | + | } | |
| 231 | + | ||
| 232 | + | // RectangleList is a borrowed view over a wire list of xproto.Rectangle. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 233 | + | type RectangleList struct{ b []byte } | |
| 234 | + | ||
| 235 | + | func (l RectangleList) Len() int { return len(l.b) / 8 } | |
| 236 | + | func (l RectangleList) At(i int) xproto.Rectangle { return xproto.GetRectangle(l.b[i*8:]) } | |
| 237 | + | ||
| 238 | + | // Uint32List is a borrowed view over a wire list of uint32. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 239 | + | type Uint32List struct{ b []byte } | |
| 240 | + | ||
| 241 | + | func (l Uint32List) Len() int { return len(l.b) / 4 } | |
| 242 | + | func (l Uint32List) At(i int) uint32 { return uint32(binary.LittleEndian.Uint32(l.b[i*4:])) } | |
A xfixes/requests_generated.go +766 -0
| @@ -0,0 +1,766 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xfixes | |
| 3 | + | ||
| 4 | + | import "bnema.dev/xturbo/render" | |
| 5 | + | import "bnema.dev/xturbo/shape" | |
| 6 | + | import "bnema.dev/xturbo/xproto" | |
| 7 | + | import "encoding/binary" | |
| 8 | + | import "bnema.dev/xturbo" | |
| 9 | + | ||
| 10 | + | func QueryVersion(b *xturbo.Buf, clientMajorVersion uint32, clientMinorVersion uint32) xturbo.Seq { | |
| 11 | + | if b.Ext == nil { | |
| 12 | + | b.Fail(xturbo.ErrExtMissing) | |
| 13 | + | return 0 | |
| 14 | + | } | |
| 15 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 16 | + | if major == 0 { | |
| 17 | + | b.Fail(xturbo.ErrExtMissing) | |
| 18 | + | return 0 | |
| 19 | + | } | |
| 20 | + | p, seq := b.Request(major, 0, 8) | |
| 21 | + | if p == nil { | |
| 22 | + | return 0 | |
| 23 | + | } | |
| 24 | + | binary.LittleEndian.PutUint32(p[0:], uint32(clientMajorVersion)) | |
| 25 | + | binary.LittleEndian.PutUint32(p[4:], uint32(clientMinorVersion)) | |
| 26 | + | return seq | |
| 27 | + | } | |
| 28 | + | ||
| 29 | + | func ChangeSaveSet(b *xturbo.Buf, mode SaveSetMode, target SaveSetTarget, map_ SaveSetMapping, window xproto.Window) xturbo.Seq { | |
| 30 | + | if b.Ext == nil { | |
| 31 | + | b.Fail(xturbo.ErrExtMissing) | |
| 32 | + | return 0 | |
| 33 | + | } | |
| 34 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 35 | + | if major == 0 { | |
| 36 | + | b.Fail(xturbo.ErrExtMissing) | |
| 37 | + | return 0 | |
| 38 | + | } | |
| 39 | + | p, seq := b.Request(major, 1, 8) | |
| 40 | + | if p == nil { | |
| 41 | + | return 0 | |
| 42 | + | } | |
| 43 | + | p[0:][0] = byte(mode) | |
| 44 | + | p[1:][0] = byte(target) | |
| 45 | + | p[2:][0] = byte(map_) | |
| 46 | + | binary.LittleEndian.PutUint32(p[4:], uint32(window)) | |
| 47 | + | return seq | |
| 48 | + | } | |
| 49 | + | ||
| 50 | + | func SelectSelectionInput(b *xturbo.Buf, window xproto.Window, selection xproto.Atom, eventMask SelectionEventMask) xturbo.Seq { | |
| 51 | + | if b.Ext == nil { | |
| 52 | + | b.Fail(xturbo.ErrExtMissing) | |
| 53 | + | return 0 | |
| 54 | + | } | |
| 55 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 56 | + | if major == 0 { | |
| 57 | + | b.Fail(xturbo.ErrExtMissing) | |
| 58 | + | return 0 | |
| 59 | + | } | |
| 60 | + | p, seq := b.Request(major, 2, 12) | |
| 61 | + | if p == nil { | |
| 62 | + | return 0 | |
| 63 | + | } | |
| 64 | + | binary.LittleEndian.PutUint32(p[0:], uint32(window)) | |
| 65 | + | binary.LittleEndian.PutUint32(p[4:], uint32(selection)) | |
| 66 | + | binary.LittleEndian.PutUint32(p[8:], uint32(eventMask)) | |
| 67 | + | return seq | |
| 68 | + | } | |
| 69 | + | ||
| 70 | + | func SelectCursorInput(b *xturbo.Buf, window xproto.Window, eventMask CursorNotifyMask) xturbo.Seq { | |
| 71 | + | if b.Ext == nil { | |
| 72 | + | b.Fail(xturbo.ErrExtMissing) | |
| 73 | + | return 0 | |
| 74 | + | } | |
| 75 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 76 | + | if major == 0 { | |
| 77 | + | b.Fail(xturbo.ErrExtMissing) | |
| 78 | + | return 0 | |
| 79 | + | } | |
| 80 | + | p, seq := b.Request(major, 3, 8) | |
| 81 | + | if p == nil { | |
| 82 | + | return 0 | |
| 83 | + | } | |
| 84 | + | binary.LittleEndian.PutUint32(p[0:], uint32(window)) | |
| 85 | + | binary.LittleEndian.PutUint32(p[4:], uint32(eventMask)) | |
| 86 | + | return seq | |
| 87 | + | } | |
| 88 | + | ||
| 89 | + | func GetCursorImage(b *xturbo.Buf) xturbo.Seq { | |
| 90 | + | if b.Ext == nil { | |
| 91 | + | b.Fail(xturbo.ErrExtMissing) | |
| 92 | + | return 0 | |
| 93 | + | } | |
| 94 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 95 | + | if major == 0 { | |
| 96 | + | b.Fail(xturbo.ErrExtMissing) | |
| 97 | + | return 0 | |
| 98 | + | } | |
| 99 | + | p, seq := b.Request(major, 4, 0) | |
| 100 | + | if p == nil { | |
| 101 | + | return 0 | |
| 102 | + | } | |
| 103 | + | return seq | |
| 104 | + | } | |
| 105 | + | ||
| 106 | + | func CreateRegion(b *xturbo.Buf, region Region, rectangles []xproto.Rectangle) xturbo.Seq { | |
| 107 | + | size := 0 | |
| 108 | + | size += 4 | |
| 109 | + | size += len(rectangles) * 8 | |
| 110 | + | size = (size + 3) &^ 3 | |
| 111 | + | if b.Ext == nil { | |
| 112 | + | b.Fail(xturbo.ErrExtMissing) | |
| 113 | + | return 0 | |
| 114 | + | } | |
| 115 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 116 | + | if major == 0 { | |
| 117 | + | b.Fail(xturbo.ErrExtMissing) | |
| 118 | + | return 0 | |
| 119 | + | } | |
| 120 | + | p, seq := b.Request(major, 5, size) | |
| 121 | + | if p == nil { | |
| 122 | + | return 0 | |
| 123 | + | } | |
| 124 | + | off := 0 | |
| 125 | + | binary.LittleEndian.PutUint32(p[off:], uint32(region)) | |
| 126 | + | off += 4 | |
| 127 | + | for i := range rectangles { | |
| 128 | + | rectangles[i].Put(p[off:]) | |
| 129 | + | off += 8 | |
| 130 | + | } | |
| 131 | + | return seq | |
| 132 | + | } | |
| 133 | + | ||
| 134 | + | func CreateRegionFromBitmap(b *xturbo.Buf, region Region, bitmap xproto.Pixmap) xturbo.Seq { | |
| 135 | + | if b.Ext == nil { | |
| 136 | + | b.Fail(xturbo.ErrExtMissing) | |
| 137 | + | return 0 | |
| 138 | + | } | |
| 139 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 140 | + | if major == 0 { | |
| 141 | + | b.Fail(xturbo.ErrExtMissing) | |
| 142 | + | return 0 | |
| 143 | + | } | |
| 144 | + | p, seq := b.Request(major, 6, 8) | |
| 145 | + | if p == nil { | |
| 146 | + | return 0 | |
| 147 | + | } | |
| 148 | + | binary.LittleEndian.PutUint32(p[0:], uint32(region)) | |
| 149 | + | binary.LittleEndian.PutUint32(p[4:], uint32(bitmap)) | |
| 150 | + | return seq | |
| 151 | + | } | |
| 152 | + | ||
| 153 | + | func CreateRegionFromWindow(b *xturbo.Buf, region Region, window xproto.Window, kind shape.Sk) xturbo.Seq { | |
| 154 | + | if b.Ext == nil { | |
| 155 | + | b.Fail(xturbo.ErrExtMissing) | |
| 156 | + | return 0 | |
| 157 | + | } | |
| 158 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 159 | + | if major == 0 { | |
| 160 | + | b.Fail(xturbo.ErrExtMissing) | |
| 161 | + | return 0 | |
| 162 | + | } | |
| 163 | + | p, seq := b.Request(major, 7, 12) | |
| 164 | + | if p == nil { | |
| 165 | + | return 0 | |
| 166 | + | } | |
| 167 | + | binary.LittleEndian.PutUint32(p[0:], uint32(region)) | |
| 168 | + | binary.LittleEndian.PutUint32(p[4:], uint32(window)) | |
| 169 | + | p[8:][0] = byte(kind) | |
| 170 | + | return seq | |
| 171 | + | } | |
| 172 | + | ||
| 173 | + | func CreateRegionFromGC(b *xturbo.Buf, region Region, gc xproto.Gcontext) xturbo.Seq { | |
| 174 | + | if b.Ext == nil { | |
| 175 | + | b.Fail(xturbo.ErrExtMissing) | |
| 176 | + | return 0 | |
| 177 | + | } | |
| 178 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 179 | + | if major == 0 { | |
| 180 | + | b.Fail(xturbo.ErrExtMissing) | |
| 181 | + | return 0 | |
| 182 | + | } | |
| 183 | + | p, seq := b.Request(major, 8, 8) | |
| 184 | + | if p == nil { | |
| 185 | + | return 0 | |
| 186 | + | } | |
| 187 | + | binary.LittleEndian.PutUint32(p[0:], uint32(region)) | |
| 188 | + | binary.LittleEndian.PutUint32(p[4:], uint32(gc)) | |
| 189 | + | return seq | |
| 190 | + | } | |
| 191 | + | ||
| 192 | + | func CreateRegionFromPicture(b *xturbo.Buf, region Region, picture render.Picture) xturbo.Seq { | |
| 193 | + | if b.Ext == nil { | |
| 194 | + | b.Fail(xturbo.ErrExtMissing) | |
| 195 | + | return 0 | |
| 196 | + | } | |
| 197 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 198 | + | if major == 0 { | |
| 199 | + | b.Fail(xturbo.ErrExtMissing) | |
| 200 | + | return 0 | |
| 201 | + | } | |
| 202 | + | p, seq := b.Request(major, 9, 8) | |
| 203 | + | if p == nil { | |
| 204 | + | return 0 | |
| 205 | + | } | |
| 206 | + | binary.LittleEndian.PutUint32(p[0:], uint32(region)) | |
| 207 | + | binary.LittleEndian.PutUint32(p[4:], uint32(picture)) | |
| 208 | + | return seq | |
| 209 | + | } | |
| 210 | + | ||
| 211 | + | func DestroyRegion(b *xturbo.Buf, region Region) xturbo.Seq { | |
| 212 | + | if b.Ext == nil { | |
| 213 | + | b.Fail(xturbo.ErrExtMissing) | |
| 214 | + | return 0 | |
| 215 | + | } | |
| 216 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 217 | + | if major == 0 { | |
| 218 | + | b.Fail(xturbo.ErrExtMissing) | |
| 219 | + | return 0 | |
| 220 | + | } | |
| 221 | + | p, seq := b.Request(major, 10, 4) | |
| 222 | + | if p == nil { | |
| 223 | + | return 0 | |
| 224 | + | } | |
| 225 | + | binary.LittleEndian.PutUint32(p[0:], uint32(region)) | |
| 226 | + | return seq | |
| 227 | + | } | |
| 228 | + | ||
| 229 | + | func SetRegion(b *xturbo.Buf, region Region, rectangles []xproto.Rectangle) xturbo.Seq { | |
| 230 | + | size := 0 | |
| 231 | + | size += 4 | |
| 232 | + | size += len(rectangles) * 8 | |
| 233 | + | size = (size + 3) &^ 3 | |
| 234 | + | if b.Ext == nil { | |
| 235 | + | b.Fail(xturbo.ErrExtMissing) | |
| 236 | + | return 0 | |
| 237 | + | } | |
| 238 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 239 | + | if major == 0 { | |
| 240 | + | b.Fail(xturbo.ErrExtMissing) | |
| 241 | + | return 0 | |
| 242 | + | } | |
| 243 | + | p, seq := b.Request(major, 11, size) | |
| 244 | + | if p == nil { | |
| 245 | + | return 0 | |
| 246 | + | } | |
| 247 | + | off := 0 | |
| 248 | + | binary.LittleEndian.PutUint32(p[off:], uint32(region)) | |
| 249 | + | off += 4 | |
| 250 | + | for i := range rectangles { | |
| 251 | + | rectangles[i].Put(p[off:]) | |
| 252 | + | off += 8 | |
| 253 | + | } | |
| 254 | + | return seq | |
| 255 | + | } | |
| 256 | + | ||
| 257 | + | func CopyRegion(b *xturbo.Buf, source Region, destination Region) xturbo.Seq { | |
| 258 | + | if b.Ext == nil { | |
| 259 | + | b.Fail(xturbo.ErrExtMissing) | |
| 260 | + | return 0 | |
| 261 | + | } | |
| 262 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 263 | + | if major == 0 { | |
| 264 | + | b.Fail(xturbo.ErrExtMissing) | |
| 265 | + | return 0 | |
| 266 | + | } | |
| 267 | + | p, seq := b.Request(major, 12, 8) | |
| 268 | + | if p == nil { | |
| 269 | + | return 0 | |
| 270 | + | } | |
| 271 | + | binary.LittleEndian.PutUint32(p[0:], uint32(source)) | |
| 272 | + | binary.LittleEndian.PutUint32(p[4:], uint32(destination)) | |
| 273 | + | return seq | |
| 274 | + | } | |
| 275 | + | ||
| 276 | + | func UnionRegion(b *xturbo.Buf, source1 Region, source2 Region, destination Region) xturbo.Seq { | |
| 277 | + | if b.Ext == nil { | |
| 278 | + | b.Fail(xturbo.ErrExtMissing) | |
| 279 | + | return 0 | |
| 280 | + | } | |
| 281 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 282 | + | if major == 0 { | |
| 283 | + | b.Fail(xturbo.ErrExtMissing) | |
| 284 | + | return 0 | |
| 285 | + | } | |
| 286 | + | p, seq := b.Request(major, 13, 12) | |
| 287 | + | if p == nil { | |
| 288 | + | return 0 | |
| 289 | + | } | |
| 290 | + | binary.LittleEndian.PutUint32(p[0:], uint32(source1)) | |
| 291 | + | binary.LittleEndian.PutUint32(p[4:], uint32(source2)) | |
| 292 | + | binary.LittleEndian.PutUint32(p[8:], uint32(destination)) | |
| 293 | + | return seq | |
| 294 | + | } | |
| 295 | + | ||
| 296 | + | func IntersectRegion(b *xturbo.Buf, source1 Region, source2 Region, destination Region) xturbo.Seq { | |
| 297 | + | if b.Ext == nil { | |
| 298 | + | b.Fail(xturbo.ErrExtMissing) | |
| 299 | + | return 0 | |
| 300 | + | } | |
| 301 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 302 | + | if major == 0 { | |
| 303 | + | b.Fail(xturbo.ErrExtMissing) | |
| 304 | + | return 0 | |
| 305 | + | } | |
| 306 | + | p, seq := b.Request(major, 14, 12) | |
| 307 | + | if p == nil { | |
| 308 | + | return 0 | |
| 309 | + | } | |
| 310 | + | binary.LittleEndian.PutUint32(p[0:], uint32(source1)) | |
| 311 | + | binary.LittleEndian.PutUint32(p[4:], uint32(source2)) | |
| 312 | + | binary.LittleEndian.PutUint32(p[8:], uint32(destination)) | |
| 313 | + | return seq | |
| 314 | + | } | |
| 315 | + | ||
| 316 | + | func SubtractRegion(b *xturbo.Buf, source1 Region, source2 Region, destination Region) xturbo.Seq { | |
| 317 | + | if b.Ext == nil { | |
| 318 | + | b.Fail(xturbo.ErrExtMissing) | |
| 319 | + | return 0 | |
| 320 | + | } | |
| 321 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 322 | + | if major == 0 { | |
| 323 | + | b.Fail(xturbo.ErrExtMissing) | |
| 324 | + | return 0 | |
| 325 | + | } | |
| 326 | + | p, seq := b.Request(major, 15, 12) | |
| 327 | + | if p == nil { | |
| 328 | + | return 0 | |
| 329 | + | } | |
| 330 | + | binary.LittleEndian.PutUint32(p[0:], uint32(source1)) | |
| 331 | + | binary.LittleEndian.PutUint32(p[4:], uint32(source2)) | |
| 332 | + | binary.LittleEndian.PutUint32(p[8:], uint32(destination)) | |
| 333 | + | return seq | |
| 334 | + | } | |
| 335 | + | ||
| 336 | + | func InvertRegion(b *xturbo.Buf, source Region, bounds xproto.Rectangle, destination Region) xturbo.Seq { | |
| 337 | + | if b.Ext == nil { | |
| 338 | + | b.Fail(xturbo.ErrExtMissing) | |
| 339 | + | return 0 | |
| 340 | + | } | |
| 341 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 342 | + | if major == 0 { | |
| 343 | + | b.Fail(xturbo.ErrExtMissing) | |
| 344 | + | return 0 | |
| 345 | + | } | |
| 346 | + | p, seq := b.Request(major, 16, 16) | |
| 347 | + | if p == nil { | |
| 348 | + | return 0 | |
| 349 | + | } | |
| 350 | + | binary.LittleEndian.PutUint32(p[0:], uint32(source)) | |
| 351 | + | bounds.Put(p[4:]) | |
| 352 | + | binary.LittleEndian.PutUint32(p[12:], uint32(destination)) | |
| 353 | + | return seq | |
| 354 | + | } | |
| 355 | + | ||
| 356 | + | func TranslateRegion(b *xturbo.Buf, region Region, dx int16, dy int16) xturbo.Seq { | |
| 357 | + | if b.Ext == nil { | |
| 358 | + | b.Fail(xturbo.ErrExtMissing) | |
| 359 | + | return 0 | |
| 360 | + | } | |
| 361 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 362 | + | if major == 0 { | |
| 363 | + | b.Fail(xturbo.ErrExtMissing) | |
| 364 | + | return 0 | |
| 365 | + | } | |
| 366 | + | p, seq := b.Request(major, 17, 8) | |
| 367 | + | if p == nil { | |
| 368 | + | return 0 | |
| 369 | + | } | |
| 370 | + | binary.LittleEndian.PutUint32(p[0:], uint32(region)) | |
| 371 | + | binary.LittleEndian.PutUint16(p[4:], uint16(dx)) | |
| 372 | + | binary.LittleEndian.PutUint16(p[6:], uint16(dy)) | |
| 373 | + | return seq | |
| 374 | + | } | |
| 375 | + | ||
| 376 | + | func RegionExtents(b *xturbo.Buf, source Region, destination Region) xturbo.Seq { | |
| 377 | + | if b.Ext == nil { | |
| 378 | + | b.Fail(xturbo.ErrExtMissing) | |
| 379 | + | return 0 | |
| 380 | + | } | |
| 381 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 382 | + | if major == 0 { | |
| 383 | + | b.Fail(xturbo.ErrExtMissing) | |
| 384 | + | return 0 | |
| 385 | + | } | |
| 386 | + | p, seq := b.Request(major, 18, 8) | |
| 387 | + | if p == nil { | |
| 388 | + | return 0 | |
| 389 | + | } | |
| 390 | + | binary.LittleEndian.PutUint32(p[0:], uint32(source)) | |
| 391 | + | binary.LittleEndian.PutUint32(p[4:], uint32(destination)) | |
| 392 | + | return seq | |
| 393 | + | } | |
| 394 | + | ||
| 395 | + | func FetchRegion(b *xturbo.Buf, region Region) xturbo.Seq { | |
| 396 | + | if b.Ext == nil { | |
| 397 | + | b.Fail(xturbo.ErrExtMissing) | |
| 398 | + | return 0 | |
| 399 | + | } | |
| 400 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 401 | + | if major == 0 { | |
| 402 | + | b.Fail(xturbo.ErrExtMissing) | |
| 403 | + | return 0 | |
| 404 | + | } | |
| 405 | + | p, seq := b.Request(major, 19, 4) | |
| 406 | + | if p == nil { | |
| 407 | + | return 0 | |
| 408 | + | } | |
| 409 | + | binary.LittleEndian.PutUint32(p[0:], uint32(region)) | |
| 410 | + | return seq | |
| 411 | + | } | |
| 412 | + | ||
| 413 | + | func SetGCClipRegion(b *xturbo.Buf, gc xproto.Gcontext, region Region, xOrigin int16, yOrigin int16) xturbo.Seq { | |
| 414 | + | if b.Ext == nil { | |
| 415 | + | b.Fail(xturbo.ErrExtMissing) | |
| 416 | + | return 0 | |
| 417 | + | } | |
| 418 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 419 | + | if major == 0 { | |
| 420 | + | b.Fail(xturbo.ErrExtMissing) | |
| 421 | + | return 0 | |
| 422 | + | } | |
| 423 | + | p, seq := b.Request(major, 20, 12) | |
| 424 | + | if p == nil { | |
| 425 | + | return 0 | |
| 426 | + | } | |
| 427 | + | binary.LittleEndian.PutUint32(p[0:], uint32(gc)) | |
| 428 | + | binary.LittleEndian.PutUint32(p[4:], uint32(region)) | |
| 429 | + | binary.LittleEndian.PutUint16(p[8:], uint16(xOrigin)) | |
| 430 | + | binary.LittleEndian.PutUint16(p[10:], uint16(yOrigin)) | |
| 431 | + | return seq | |
| 432 | + | } | |
| 433 | + | ||
| 434 | + | func SetWindowShapeRegion(b *xturbo.Buf, dest xproto.Window, destKind shape.Sk, xOffset int16, yOffset int16, region Region) xturbo.Seq { | |
| 435 | + | if b.Ext == nil { | |
| 436 | + | b.Fail(xturbo.ErrExtMissing) | |
| 437 | + | return 0 | |
| 438 | + | } | |
| 439 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 440 | + | if major == 0 { | |
| 441 | + | b.Fail(xturbo.ErrExtMissing) | |
| 442 | + | return 0 | |
| 443 | + | } | |
| 444 | + | p, seq := b.Request(major, 21, 16) | |
| 445 | + | if p == nil { | |
| 446 | + | return 0 | |
| 447 | + | } | |
| 448 | + | binary.LittleEndian.PutUint32(p[0:], uint32(dest)) | |
| 449 | + | p[4:][0] = byte(destKind) | |
| 450 | + | binary.LittleEndian.PutUint16(p[8:], uint16(xOffset)) | |
| 451 | + | binary.LittleEndian.PutUint16(p[10:], uint16(yOffset)) | |
| 452 | + | binary.LittleEndian.PutUint32(p[12:], uint32(region)) | |
| 453 | + | return seq | |
| 454 | + | } | |
| 455 | + | ||
| 456 | + | func SetPictureClipRegion(b *xturbo.Buf, picture render.Picture, region Region, xOrigin int16, yOrigin int16) xturbo.Seq { | |
| 457 | + | if b.Ext == nil { | |
| 458 | + | b.Fail(xturbo.ErrExtMissing) | |
| 459 | + | return 0 | |
| 460 | + | } | |
| 461 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 462 | + | if major == 0 { | |
| 463 | + | b.Fail(xturbo.ErrExtMissing) | |
| 464 | + | return 0 | |
| 465 | + | } | |
| 466 | + | p, seq := b.Request(major, 22, 12) | |
| 467 | + | if p == nil { | |
| 468 | + | return 0 | |
| 469 | + | } | |
| 470 | + | binary.LittleEndian.PutUint32(p[0:], uint32(picture)) | |
| 471 | + | binary.LittleEndian.PutUint32(p[4:], uint32(region)) | |
| 472 | + | binary.LittleEndian.PutUint16(p[8:], uint16(xOrigin)) | |
| 473 | + | binary.LittleEndian.PutUint16(p[10:], uint16(yOrigin)) | |
| 474 | + | return seq | |
| 475 | + | } | |
| 476 | + | ||
| 477 | + | func SetCursorName(b *xturbo.Buf, cursor xproto.Cursor, name string) xturbo.Seq { | |
| 478 | + | if uint64(len(name)) > 65535 { | |
| 479 | + | b.Fail(xturbo.ErrBadLength) | |
| 480 | + | return 0 | |
| 481 | + | } | |
| 482 | + | size := 0 | |
| 483 | + | size += 4 | |
| 484 | + | size += 2 | |
| 485 | + | size += 2 | |
| 486 | + | size += len(name) * 1 | |
| 487 | + | size = (size + 3) &^ 3 | |
| 488 | + | if b.Ext == nil { | |
| 489 | + | b.Fail(xturbo.ErrExtMissing) | |
| 490 | + | return 0 | |
| 491 | + | } | |
| 492 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 493 | + | if major == 0 { | |
| 494 | + | b.Fail(xturbo.ErrExtMissing) | |
| 495 | + | return 0 | |
| 496 | + | } | |
| 497 | + | p, seq := b.Request(major, 23, size) | |
| 498 | + | if p == nil { | |
| 499 | + | return 0 | |
| 500 | + | } | |
| 501 | + | off := 0 | |
| 502 | + | binary.LittleEndian.PutUint32(p[off:], uint32(cursor)) | |
| 503 | + | off += 4 | |
| 504 | + | binary.LittleEndian.PutUint16(p[off:], uint16(len(name))) | |
| 505 | + | off += 2 | |
| 506 | + | off += 2 | |
| 507 | + | copy(p[off:], name) | |
| 508 | + | off += len(name) | |
| 509 | + | return seq | |
| 510 | + | } | |
| 511 | + | ||
| 512 | + | func GetCursorName(b *xturbo.Buf, cursor xproto.Cursor) xturbo.Seq { | |
| 513 | + | if b.Ext == nil { | |
| 514 | + | b.Fail(xturbo.ErrExtMissing) | |
| 515 | + | return 0 | |
| 516 | + | } | |
| 517 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 518 | + | if major == 0 { | |
| 519 | + | b.Fail(xturbo.ErrExtMissing) | |
| 520 | + | return 0 | |
| 521 | + | } | |
| 522 | + | p, seq := b.Request(major, 24, 4) | |
| 523 | + | if p == nil { | |
| 524 | + | return 0 | |
| 525 | + | } | |
| 526 | + | binary.LittleEndian.PutUint32(p[0:], uint32(cursor)) | |
| 527 | + | return seq | |
| 528 | + | } | |
| 529 | + | ||
| 530 | + | func GetCursorImageAndName(b *xturbo.Buf) xturbo.Seq { | |
| 531 | + | if b.Ext == nil { | |
| 532 | + | b.Fail(xturbo.ErrExtMissing) | |
| 533 | + | return 0 | |
| 534 | + | } | |
| 535 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 536 | + | if major == 0 { | |
| 537 | + | b.Fail(xturbo.ErrExtMissing) | |
| 538 | + | return 0 | |
| 539 | + | } | |
| 540 | + | p, seq := b.Request(major, 25, 0) | |
| 541 | + | if p == nil { | |
| 542 | + | return 0 | |
| 543 | + | } | |
| 544 | + | return seq | |
| 545 | + | } | |
| 546 | + | ||
| 547 | + | func ChangeCursor(b *xturbo.Buf, source xproto.Cursor, destination xproto.Cursor) xturbo.Seq { | |
| 548 | + | if b.Ext == nil { | |
| 549 | + | b.Fail(xturbo.ErrExtMissing) | |
| 550 | + | return 0 | |
| 551 | + | } | |
| 552 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 553 | + | if major == 0 { | |
| 554 | + | b.Fail(xturbo.ErrExtMissing) | |
| 555 | + | return 0 | |
| 556 | + | } | |
| 557 | + | p, seq := b.Request(major, 26, 8) | |
| 558 | + | if p == nil { | |
| 559 | + | return 0 | |
| 560 | + | } | |
| 561 | + | binary.LittleEndian.PutUint32(p[0:], uint32(source)) | |
| 562 | + | binary.LittleEndian.PutUint32(p[4:], uint32(destination)) | |
| 563 | + | return seq | |
| 564 | + | } | |
| 565 | + | ||
| 566 | + | func ChangeCursorByName(b *xturbo.Buf, src xproto.Cursor, name string) xturbo.Seq { | |
| 567 | + | if uint64(len(name)) > 65535 { | |
| 568 | + | b.Fail(xturbo.ErrBadLength) | |
| 569 | + | return 0 | |
| 570 | + | } | |
| 571 | + | size := 0 | |
| 572 | + | size += 4 | |
| 573 | + | size += 2 | |
| 574 | + | size += 2 | |
| 575 | + | size += len(name) * 1 | |
| 576 | + | size = (size + 3) &^ 3 | |
| 577 | + | if b.Ext == nil { | |
| 578 | + | b.Fail(xturbo.ErrExtMissing) | |
| 579 | + | return 0 | |
| 580 | + | } | |
| 581 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 582 | + | if major == 0 { | |
| 583 | + | b.Fail(xturbo.ErrExtMissing) | |
| 584 | + | return 0 | |
| 585 | + | } | |
| 586 | + | p, seq := b.Request(major, 27, size) | |
| 587 | + | if p == nil { | |
| 588 | + | return 0 | |
| 589 | + | } | |
| 590 | + | off := 0 | |
| 591 | + | binary.LittleEndian.PutUint32(p[off:], uint32(src)) | |
| 592 | + | off += 4 | |
| 593 | + | binary.LittleEndian.PutUint16(p[off:], uint16(len(name))) | |
| 594 | + | off += 2 | |
| 595 | + | off += 2 | |
| 596 | + | copy(p[off:], name) | |
| 597 | + | off += len(name) | |
| 598 | + | return seq | |
| 599 | + | } | |
| 600 | + | ||
| 601 | + | func ExpandRegion(b *xturbo.Buf, source Region, destination Region, left uint16, right uint16, top uint16, bottom uint16) xturbo.Seq { | |
| 602 | + | if b.Ext == nil { | |
| 603 | + | b.Fail(xturbo.ErrExtMissing) | |
| 604 | + | return 0 | |
| 605 | + | } | |
| 606 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 607 | + | if major == 0 { | |
| 608 | + | b.Fail(xturbo.ErrExtMissing) | |
| 609 | + | return 0 | |
| 610 | + | } | |
| 611 | + | p, seq := b.Request(major, 28, 16) | |
| 612 | + | if p == nil { | |
| 613 | + | return 0 | |
| 614 | + | } | |
| 615 | + | binary.LittleEndian.PutUint32(p[0:], uint32(source)) | |
| 616 | + | binary.LittleEndian.PutUint32(p[4:], uint32(destination)) | |
| 617 | + | binary.LittleEndian.PutUint16(p[8:], uint16(left)) | |
| 618 | + | binary.LittleEndian.PutUint16(p[10:], uint16(right)) | |
| 619 | + | binary.LittleEndian.PutUint16(p[12:], uint16(top)) | |
| 620 | + | binary.LittleEndian.PutUint16(p[14:], uint16(bottom)) | |
| 621 | + | return seq | |
| 622 | + | } | |
| 623 | + | ||
| 624 | + | func HideCursor(b *xturbo.Buf, window xproto.Window) xturbo.Seq { | |
| 625 | + | if b.Ext == nil { | |
| 626 | + | b.Fail(xturbo.ErrExtMissing) | |
| 627 | + | return 0 | |
| 628 | + | } | |
| 629 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 630 | + | if major == 0 { | |
| 631 | + | b.Fail(xturbo.ErrExtMissing) | |
| 632 | + | return 0 | |
| 633 | + | } | |
| 634 | + | p, seq := b.Request(major, 29, 4) | |
| 635 | + | if p == nil { | |
| 636 | + | return 0 | |
| 637 | + | } | |
| 638 | + | binary.LittleEndian.PutUint32(p[0:], uint32(window)) | |
| 639 | + | return seq | |
| 640 | + | } | |
| 641 | + | ||
| 642 | + | func ShowCursor(b *xturbo.Buf, window xproto.Window) xturbo.Seq { | |
| 643 | + | if b.Ext == nil { | |
| 644 | + | b.Fail(xturbo.ErrExtMissing) | |
| 645 | + | return 0 | |
| 646 | + | } | |
| 647 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 648 | + | if major == 0 { | |
| 649 | + | b.Fail(xturbo.ErrExtMissing) | |
| 650 | + | return 0 | |
| 651 | + | } | |
| 652 | + | p, seq := b.Request(major, 30, 4) | |
| 653 | + | if p == nil { | |
| 654 | + | return 0 | |
| 655 | + | } | |
| 656 | + | binary.LittleEndian.PutUint32(p[0:], uint32(window)) | |
| 657 | + | return seq | |
| 658 | + | } | |
| 659 | + | ||
| 660 | + | func CreatePointerBarrier(b *xturbo.Buf, barrier Barrier, window xproto.Window, x1 uint16, y1 uint16, x2 uint16, y2 uint16, directions BarrierDirections, devices []uint16) xturbo.Seq { | |
| 661 | + | if uint64(len(devices)) > 65535 { | |
| 662 | + | b.Fail(xturbo.ErrBadLength) | |
| 663 | + | return 0 | |
| 664 | + | } | |
| 665 | + | size := 0 | |
| 666 | + | size += 4 | |
| 667 | + | size += 4 | |
| 668 | + | size += 2 | |
| 669 | + | size += 2 | |
| 670 | + | size += 2 | |
| 671 | + | size += 2 | |
| 672 | + | size += 4 | |
| 673 | + | size += 2 | |
| 674 | + | size += 2 | |
| 675 | + | size += len(devices) * 2 | |
| 676 | + | size = (size + 3) &^ 3 | |
| 677 | + | if b.Ext == nil { | |
| 678 | + | b.Fail(xturbo.ErrExtMissing) | |
| 679 | + | return 0 | |
| 680 | + | } | |
| 681 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 682 | + | if major == 0 { | |
| 683 | + | b.Fail(xturbo.ErrExtMissing) | |
| 684 | + | return 0 | |
| 685 | + | } | |
| 686 | + | p, seq := b.Request(major, 31, size) | |
| 687 | + | if p == nil { | |
| 688 | + | return 0 | |
| 689 | + | } | |
| 690 | + | off := 0 | |
| 691 | + | binary.LittleEndian.PutUint32(p[off:], uint32(barrier)) | |
| 692 | + | off += 4 | |
| 693 | + | binary.LittleEndian.PutUint32(p[off:], uint32(window)) | |
| 694 | + | off += 4 | |
| 695 | + | binary.LittleEndian.PutUint16(p[off:], uint16(x1)) | |
| 696 | + | off += 2 | |
| 697 | + | binary.LittleEndian.PutUint16(p[off:], uint16(y1)) | |
| 698 | + | off += 2 | |
| 699 | + | binary.LittleEndian.PutUint16(p[off:], uint16(x2)) | |
| 700 | + | off += 2 | |
| 701 | + | binary.LittleEndian.PutUint16(p[off:], uint16(y2)) | |
| 702 | + | off += 2 | |
| 703 | + | binary.LittleEndian.PutUint32(p[off:], uint32(directions)) | |
| 704 | + | off += 4 | |
| 705 | + | off += 2 | |
| 706 | + | binary.LittleEndian.PutUint16(p[off:], uint16(len(devices))) | |
| 707 | + | off += 2 | |
| 708 | + | for i := range devices { | |
| 709 | + | binary.LittleEndian.PutUint16(p[off:], uint16(devices[i])) | |
| 710 | + | off += 2 | |
| 711 | + | } | |
| 712 | + | return seq | |
| 713 | + | } | |
| 714 | + | ||
| 715 | + | func DeletePointerBarrier(b *xturbo.Buf, barrier Barrier) xturbo.Seq { | |
| 716 | + | if b.Ext == nil { | |
| 717 | + | b.Fail(xturbo.ErrExtMissing) | |
| 718 | + | return 0 | |
| 719 | + | } | |
| 720 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 721 | + | if major == 0 { | |
| 722 | + | b.Fail(xturbo.ErrExtMissing) | |
| 723 | + | return 0 | |
| 724 | + | } | |
| 725 | + | p, seq := b.Request(major, 32, 4) | |
| 726 | + | if p == nil { | |
| 727 | + | return 0 | |
| 728 | + | } | |
| 729 | + | binary.LittleEndian.PutUint32(p[0:], uint32(barrier)) | |
| 730 | + | return seq | |
| 731 | + | } | |
| 732 | + | ||
| 733 | + | func SetClientDisconnectMode(b *xturbo.Buf, disconnectMode ClientDisconnectFlags) xturbo.Seq { | |
| 734 | + | if b.Ext == nil { | |
| 735 | + | b.Fail(xturbo.ErrExtMissing) | |
| 736 | + | return 0 | |
| 737 | + | } | |
| 738 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 739 | + | if major == 0 { | |
| 740 | + | b.Fail(xturbo.ErrExtMissing) | |
| 741 | + | return 0 | |
| 742 | + | } | |
| 743 | + | p, seq := b.Request(major, 33, 4) | |
| 744 | + | if p == nil { | |
| 745 | + | return 0 | |
| 746 | + | } | |
| 747 | + | binary.LittleEndian.PutUint32(p[0:], uint32(disconnectMode)) | |
| 748 | + | return seq | |
| 749 | + | } | |
| 750 | + | ||
| 751 | + | func GetClientDisconnectMode(b *xturbo.Buf) xturbo.Seq { | |
| 752 | + | if b.Ext == nil { | |
| 753 | + | b.Fail(xturbo.ErrExtMissing) | |
| 754 | + | return 0 | |
| 755 | + | } | |
| 756 | + | major := b.Ext.Major(xturbo.ExtXFixes) | |
| 757 | + | if major == 0 { | |
| 758 | + | b.Fail(xturbo.ErrExtMissing) | |
| 759 | + | return 0 | |
| 760 | + | } | |
| 761 | + | p, seq := b.Request(major, 34, 0) | |
| 762 | + | if p == nil { | |
| 763 | + | return 0 | |
| 764 | + | } | |
| 765 | + | return seq | |
| 766 | + | } | |
A xfixes/sizes_test.go +32 -0
| @@ -0,0 +1,32 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xfixes | |
| 3 | + | ||
| 4 | + | import "testing" | |
| 5 | + | ||
| 6 | + | func TestWireSizes(t *testing.T) { | |
| 7 | + | if got := 32; got != 32 { | |
| 8 | + | t.Errorf("reply QueryVersion fixed size = %d", got) | |
| 9 | + | } | |
| 10 | + | if got := 32; got != 32 { | |
| 11 | + | t.Errorf("event SelectionNotify fixed size = %d", got) | |
| 12 | + | } | |
| 13 | + | if got := 32; got != 32 { | |
| 14 | + | t.Errorf("event CursorNotify fixed size = %d", got) | |
| 15 | + | } | |
| 16 | + | if got := 32; got != 32 { | |
| 17 | + | t.Errorf("reply GetCursorImage fixed size = %d", got) | |
| 18 | + | } | |
| 19 | + | if got := 32; got != 32 { | |
| 20 | + | t.Errorf("reply FetchRegion fixed size = %d", got) | |
| 21 | + | } | |
| 22 | + | if got := 32; got != 32 { | |
| 23 | + | t.Errorf("reply GetCursorName fixed size = %d", got) | |
| 24 | + | } | |
| 25 | + | if got := 32; got != 32 { | |
| 26 | + | t.Errorf("reply GetCursorImageAndName fixed size = %d", got) | |
| 27 | + | } | |
| 28 | + | if got := 32; got != 32 { | |
| 29 | + | t.Errorf("reply GetClientDisconnectMode fixed size = %d", got) | |
| 30 | + | } | |
| 31 | + | ||
| 32 | + | } | |
A xfixes/types_generated.go +55 -0
| @@ -0,0 +1,55 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xfixes | |
| 3 | + | ||
| 4 | + | type Region uint32 | |
| 5 | + | ||
| 6 | + | type Barrier uint32 | |
| 7 | + | ||
| 8 | + | type SaveSetMode uint8 | |
| 9 | + | ||
| 10 | + | const SaveSetModeInsert SaveSetMode = 0 | |
| 11 | + | const SaveSetModeDelete SaveSetMode = 1 | |
| 12 | + | ||
| 13 | + | type SaveSetTarget uint8 | |
| 14 | + | ||
| 15 | + | const SaveSetTargetNearest SaveSetTarget = 0 | |
| 16 | + | const SaveSetTargetRoot SaveSetTarget = 1 | |
| 17 | + | ||
| 18 | + | type SaveSetMapping uint8 | |
| 19 | + | ||
| 20 | + | const SaveSetMappingMap SaveSetMapping = 0 | |
| 21 | + | const SaveSetMappingUnmap SaveSetMapping = 1 | |
| 22 | + | ||
| 23 | + | type SelectionEvent uint8 | |
| 24 | + | ||
| 25 | + | const SelectionEventSetSelectionOwner SelectionEvent = 0 | |
| 26 | + | const SelectionEventSelectionWindowDestroy SelectionEvent = 1 | |
| 27 | + | const SelectionEventSelectionClientClose SelectionEvent = 2 | |
| 28 | + | ||
| 29 | + | type SelectionEventMask uint32 | |
| 30 | + | ||
| 31 | + | const SelectionEventMaskSetSelectionOwner SelectionEventMask = 1 | |
| 32 | + | const SelectionEventMaskSelectionWindowDestroy SelectionEventMask = 2 | |
| 33 | + | const SelectionEventMaskSelectionClientClose SelectionEventMask = 4 | |
| 34 | + | ||
| 35 | + | type CursorNotify uint8 | |
| 36 | + | ||
| 37 | + | const CursorNotifyDisplayCursor CursorNotify = 0 | |
| 38 | + | ||
| 39 | + | type CursorNotifyMask uint32 | |
| 40 | + | ||
| 41 | + | const CursorNotifyMaskDisplayCursor CursorNotifyMask = 1 | |
| 42 | + | ||
| 43 | + | const RegionNone Region = 0 | |
| 44 | + | ||
| 45 | + | type BarrierDirections uint32 | |
| 46 | + | ||
| 47 | + | const BarrierDirectionsPositiveX BarrierDirections = 1 | |
| 48 | + | const BarrierDirectionsPositiveY BarrierDirections = 2 | |
| 49 | + | const BarrierDirectionsNegativeX BarrierDirections = 4 | |
| 50 | + | const BarrierDirectionsNegativeY BarrierDirections = 8 | |
| 51 | + | ||
| 52 | + | type ClientDisconnectFlags uint32 | |
| 53 | + | ||
| 54 | + | const ClientDisconnectFlagsDefault ClientDisconnectFlags = 0 | |
| 55 | + | const ClientDisconnectFlagsTerminate ClientDisconnectFlags = 1 | |
A xproto/replies_fuzz_test.go +895 -0
| @@ -0,0 +1,895 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xproto | |
| 3 | + | ||
| 4 | + | import "testing" | |
| 5 | + | import "bnema.dev/xturbo/internal/xtest" | |
| 6 | + | ||
| 7 | + | func FuzzParseGetWindowAttributesReply(f *testing.F) { | |
| 8 | + | f.Add(make([]byte, 44)) | |
| 9 | + | if raw, err := xtest.LoadHex("../testdata/golden/xproto/GetWindowAttributes.reply.hex"); err != nil { | |
| 10 | + | f.Fatal(err) | |
| 11 | + | } else { | |
| 12 | + | f.Add(raw) | |
| 13 | + | } | |
| 14 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 15 | + | r, ok := ParseGetWindowAttributesReply(raw) | |
| 16 | + | if !ok { | |
| 17 | + | if len(raw) >= 44 { | |
| 18 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 19 | + | } | |
| 20 | + | return | |
| 21 | + | } | |
| 22 | + | if len(r.Raw()) != len(raw) { | |
| 23 | + | t.Fatal("Raw must return the parsed bytes") | |
| 24 | + | } | |
| 25 | + | _ = r.BackingStore() | |
| 26 | + | _ = r.Visual() | |
| 27 | + | _ = r.Class() | |
| 28 | + | _ = r.BitGravity() | |
| 29 | + | _ = r.WinGravity() | |
| 30 | + | _ = r.BackingPlanes() | |
| 31 | + | _ = r.BackingPixel() | |
| 32 | + | _ = r.SaveUnder() | |
| 33 | + | _ = r.MapIsInstalled() | |
| 34 | + | _ = r.MapState() | |
| 35 | + | _ = r.OverrideRedirect() | |
| 36 | + | _ = r.Colormap() | |
| 37 | + | _ = r.AllEventMasks() | |
| 38 | + | _ = r.YourEventMask() | |
| 39 | + | _ = r.DoNotPropagateMask() | |
| 40 | + | }) | |
| 41 | + | } | |
| 42 | + | ||
| 43 | + | func FuzzParseGetGeometryReply(f *testing.F) { | |
| 44 | + | f.Add(make([]byte, 32)) | |
| 45 | + | if raw, err := xtest.LoadHex("../testdata/golden/xproto/GetGeometry.reply.hex"); err != nil { | |
| 46 | + | f.Fatal(err) | |
| 47 | + | } else { | |
| 48 | + | f.Add(raw) | |
| 49 | + | } | |
| 50 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 51 | + | r, ok := ParseGetGeometryReply(raw) | |
| 52 | + | if !ok { | |
| 53 | + | if len(raw) >= 32 { | |
| 54 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 55 | + | } | |
| 56 | + | return | |
| 57 | + | } | |
| 58 | + | if len(r.Raw()) != len(raw) { | |
| 59 | + | t.Fatal("Raw must return the parsed bytes") | |
| 60 | + | } | |
| 61 | + | _ = r.Depth() | |
| 62 | + | _ = r.Root() | |
| 63 | + | _ = r.X() | |
| 64 | + | _ = r.Y() | |
| 65 | + | _ = r.Width() | |
| 66 | + | _ = r.Height() | |
| 67 | + | _ = r.BorderWidth() | |
| 68 | + | }) | |
| 69 | + | } | |
| 70 | + | ||
| 71 | + | func FuzzParseQueryTreeReply(f *testing.F) { | |
| 72 | + | f.Add(make([]byte, 32)) | |
| 73 | + | if raw, err := xtest.LoadHex("../testdata/golden/xproto/QueryTree.reply.hex"); err != nil { | |
| 74 | + | f.Fatal(err) | |
| 75 | + | } else { | |
| 76 | + | f.Add(raw) | |
| 77 | + | } | |
| 78 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 79 | + | r, ok := ParseQueryTreeReply(raw) | |
| 80 | + | if !ok { | |
| 81 | + | return | |
| 82 | + | } | |
| 83 | + | if len(r.Raw()) != len(raw) { | |
| 84 | + | t.Fatal("Raw must return the parsed bytes") | |
| 85 | + | } | |
| 86 | + | _ = r.Root() | |
| 87 | + | _ = r.Parent() | |
| 88 | + | _ = r.ChildrenLen() | |
| 89 | + | { | |
| 90 | + | l0 := r.Children() | |
| 91 | + | for i := 0; i < l0.Len(); i++ { | |
| 92 | + | _ = l0.At(i) | |
| 93 | + | } | |
| 94 | + | } | |
| 95 | + | }) | |
| 96 | + | } | |
| 97 | + | ||
| 98 | + | func FuzzParseInternAtomReply(f *testing.F) { | |
| 99 | + | f.Add(make([]byte, 32)) | |
| 100 | + | if raw, err := xtest.LoadHex("../testdata/golden/xproto/InternAtom.reply.hex"); err != nil { | |
| 101 | + | f.Fatal(err) | |
| 102 | + | } else { | |
| 103 | + | f.Add(raw) | |
| 104 | + | } | |
| 105 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 106 | + | r, ok := ParseInternAtomReply(raw) | |
| 107 | + | if !ok { | |
| 108 | + | if len(raw) >= 32 { | |
| 109 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 110 | + | } | |
| 111 | + | return | |
| 112 | + | } | |
| 113 | + | if len(r.Raw()) != len(raw) { | |
| 114 | + | t.Fatal("Raw must return the parsed bytes") | |
| 115 | + | } | |
| 116 | + | _ = r.Atom() | |
| 117 | + | }) | |
| 118 | + | } | |
| 119 | + | ||
| 120 | + | func FuzzParseGetAtomNameReply(f *testing.F) { | |
| 121 | + | f.Add(make([]byte, 32)) | |
| 122 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 123 | + | r, ok := ParseGetAtomNameReply(raw) | |
| 124 | + | if !ok { | |
| 125 | + | return | |
| 126 | + | } | |
| 127 | + | if len(r.Raw()) != len(raw) { | |
| 128 | + | t.Fatal("Raw must return the parsed bytes") | |
| 129 | + | } | |
| 130 | + | _ = r.NameLen() | |
| 131 | + | _ = len(r.Name()) | |
| 132 | + | }) | |
| 133 | + | } | |
| 134 | + | ||
| 135 | + | func FuzzParseGetPropertyReply(f *testing.F) { | |
| 136 | + | f.Add(make([]byte, 32)) | |
| 137 | + | if raw, err := xtest.LoadHex("../testdata/golden/xproto/GetProperty.reply.hex"); err != nil { | |
| 138 | + | f.Fatal(err) | |
| 139 | + | } else { | |
| 140 | + | f.Add(raw) | |
| 141 | + | } | |
| 142 | + | if raw, err := xtest.LoadHex("../testdata/golden/xproto/GetPropertyEmpty.reply.hex"); err != nil { | |
| 143 | + | f.Fatal(err) | |
| 144 | + | } else { | |
| 145 | + | f.Add(raw) | |
| 146 | + | } | |
| 147 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 148 | + | r, ok := ParseGetPropertyReply(raw) | |
| 149 | + | if !ok { | |
| 150 | + | return | |
| 151 | + | } | |
| 152 | + | if len(r.Raw()) != len(raw) { | |
| 153 | + | t.Fatal("Raw must return the parsed bytes") | |
| 154 | + | } | |
| 155 | + | _ = r.Format() | |
| 156 | + | _ = r.Type() | |
| 157 | + | _ = r.BytesAfter() | |
| 158 | + | _ = r.ValueLen() | |
| 159 | + | _ = len(r.Value()) | |
| 160 | + | }) | |
| 161 | + | } | |
| 162 | + | ||
| 163 | + | func FuzzParseListPropertiesReply(f *testing.F) { | |
| 164 | + | f.Add(make([]byte, 32)) | |
| 165 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 166 | + | r, ok := ParseListPropertiesReply(raw) | |
| 167 | + | if !ok { | |
| 168 | + | return | |
| 169 | + | } | |
| 170 | + | if len(r.Raw()) != len(raw) { | |
| 171 | + | t.Fatal("Raw must return the parsed bytes") | |
| 172 | + | } | |
| 173 | + | _ = r.AtomsLen() | |
| 174 | + | { | |
| 175 | + | l0 := r.Atoms() | |
| 176 | + | for i := 0; i < l0.Len(); i++ { | |
| 177 | + | _ = l0.At(i) | |
| 178 | + | } | |
| 179 | + | } | |
| 180 | + | }) | |
| 181 | + | } | |
| 182 | + | ||
| 183 | + | func FuzzParseGetSelectionOwnerReply(f *testing.F) { | |
| 184 | + | f.Add(make([]byte, 32)) | |
| 185 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 186 | + | r, ok := ParseGetSelectionOwnerReply(raw) | |
| 187 | + | if !ok { | |
| 188 | + | if len(raw) >= 32 { | |
| 189 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 190 | + | } | |
| 191 | + | return | |
| 192 | + | } | |
| 193 | + | if len(r.Raw()) != len(raw) { | |
| 194 | + | t.Fatal("Raw must return the parsed bytes") | |
| 195 | + | } | |
| 196 | + | _ = r.Owner() | |
| 197 | + | }) | |
| 198 | + | } | |
| 199 | + | ||
| 200 | + | func FuzzParseGrabPointerReply(f *testing.F) { | |
| 201 | + | f.Add(make([]byte, 32)) | |
| 202 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 203 | + | r, ok := ParseGrabPointerReply(raw) | |
| 204 | + | if !ok { | |
| 205 | + | if len(raw) >= 32 { | |
| 206 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 207 | + | } | |
| 208 | + | return | |
| 209 | + | } | |
| 210 | + | if len(r.Raw()) != len(raw) { | |
| 211 | + | t.Fatal("Raw must return the parsed bytes") | |
| 212 | + | } | |
| 213 | + | _ = r.Status() | |
| 214 | + | }) | |
| 215 | + | } | |
| 216 | + | ||
| 217 | + | func FuzzParseGrabKeyboardReply(f *testing.F) { | |
| 218 | + | f.Add(make([]byte, 32)) | |
| 219 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 220 | + | r, ok := ParseGrabKeyboardReply(raw) | |
| 221 | + | if !ok { | |
| 222 | + | if len(raw) >= 32 { | |
| 223 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 224 | + | } | |
| 225 | + | return | |
| 226 | + | } | |
| 227 | + | if len(r.Raw()) != len(raw) { | |
| 228 | + | t.Fatal("Raw must return the parsed bytes") | |
| 229 | + | } | |
| 230 | + | _ = r.Status() | |
| 231 | + | }) | |
| 232 | + | } | |
| 233 | + | ||
| 234 | + | func FuzzParseQueryPointerReply(f *testing.F) { | |
| 235 | + | f.Add(make([]byte, 32)) | |
| 236 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 237 | + | r, ok := ParseQueryPointerReply(raw) | |
| 238 | + | if !ok { | |
| 239 | + | if len(raw) >= 32 { | |
| 240 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 241 | + | } | |
| 242 | + | return | |
| 243 | + | } | |
| 244 | + | if len(r.Raw()) != len(raw) { | |
| 245 | + | t.Fatal("Raw must return the parsed bytes") | |
| 246 | + | } | |
| 247 | + | _ = r.SameScreen() | |
| 248 | + | _ = r.Root() | |
| 249 | + | _ = r.Child() | |
| 250 | + | _ = r.RootX() | |
| 251 | + | _ = r.RootY() | |
| 252 | + | _ = r.WinX() | |
| 253 | + | _ = r.WinY() | |
| 254 | + | _ = r.Mask() | |
| 255 | + | }) | |
| 256 | + | } | |
| 257 | + | ||
| 258 | + | func FuzzParseGetMotionEventsReply(f *testing.F) { | |
| 259 | + | f.Add(make([]byte, 32)) | |
| 260 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 261 | + | r, ok := ParseGetMotionEventsReply(raw) | |
| 262 | + | if !ok { | |
| 263 | + | return | |
| 264 | + | } | |
| 265 | + | if len(r.Raw()) != len(raw) { | |
| 266 | + | t.Fatal("Raw must return the parsed bytes") | |
| 267 | + | } | |
| 268 | + | _ = r.EventsLen() | |
| 269 | + | { | |
| 270 | + | l0 := r.Events() | |
| 271 | + | for i := 0; i < l0.Len(); i++ { | |
| 272 | + | _ = l0.At(i) | |
| 273 | + | } | |
| 274 | + | } | |
| 275 | + | }) | |
| 276 | + | } | |
| 277 | + | ||
| 278 | + | func FuzzParseTranslateCoordinatesReply(f *testing.F) { | |
| 279 | + | f.Add(make([]byte, 32)) | |
| 280 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 281 | + | r, ok := ParseTranslateCoordinatesReply(raw) | |
| 282 | + | if !ok { | |
| 283 | + | if len(raw) >= 32 { | |
| 284 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 285 | + | } | |
| 286 | + | return | |
| 287 | + | } | |
| 288 | + | if len(r.Raw()) != len(raw) { | |
| 289 | + | t.Fatal("Raw must return the parsed bytes") | |
| 290 | + | } | |
| 291 | + | _ = r.SameScreen() | |
| 292 | + | _ = r.Child() | |
| 293 | + | _ = r.DstX() | |
| 294 | + | _ = r.DstY() | |
| 295 | + | }) | |
| 296 | + | } | |
| 297 | + | ||
| 298 | + | func FuzzParseGetInputFocusReply(f *testing.F) { | |
| 299 | + | f.Add(make([]byte, 32)) | |
| 300 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 301 | + | r, ok := ParseGetInputFocusReply(raw) | |
| 302 | + | if !ok { | |
| 303 | + | if len(raw) >= 32 { | |
| 304 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 305 | + | } | |
| 306 | + | return | |
| 307 | + | } | |
| 308 | + | if len(r.Raw()) != len(raw) { | |
| 309 | + | t.Fatal("Raw must return the parsed bytes") | |
| 310 | + | } | |
| 311 | + | _ = r.RevertTo() | |
| 312 | + | _ = r.Focus() | |
| 313 | + | }) | |
| 314 | + | } | |
| 315 | + | ||
| 316 | + | func FuzzParseQueryKeymapReply(f *testing.F) { | |
| 317 | + | f.Add(make([]byte, 40)) | |
| 318 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 319 | + | r, ok := ParseQueryKeymapReply(raw) | |
| 320 | + | if !ok { | |
| 321 | + | if len(raw) >= 40 { | |
| 322 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 323 | + | } | |
| 324 | + | return | |
| 325 | + | } | |
| 326 | + | if len(r.Raw()) != len(raw) { | |
| 327 | + | t.Fatal("Raw must return the parsed bytes") | |
| 328 | + | } | |
| 329 | + | _ = len(r.Keys()) | |
| 330 | + | }) | |
| 331 | + | } | |
| 332 | + | ||
| 333 | + | func FuzzParseQueryFontReply(f *testing.F) { | |
| 334 | + | f.Add(make([]byte, 60)) | |
| 335 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 336 | + | r, ok := ParseQueryFontReply(raw) | |
| 337 | + | if !ok { | |
| 338 | + | return | |
| 339 | + | } | |
| 340 | + | if len(r.Raw()) != len(raw) { | |
| 341 | + | t.Fatal("Raw must return the parsed bytes") | |
| 342 | + | } | |
| 343 | + | _ = r.MinBounds() | |
| 344 | + | _ = r.MaxBounds() | |
| 345 | + | _ = r.MinCharOrByte2() | |
| 346 | + | _ = r.MaxCharOrByte2() | |
| 347 | + | _ = r.DefaultChar() | |
| 348 | + | _ = r.PropertiesLen() | |
| 349 | + | _ = r.DrawDirection() | |
| 350 | + | _ = r.MinByte1() | |
| 351 | + | _ = r.MaxByte1() | |
| 352 | + | _ = r.AllCharsExist() | |
| 353 | + | _ = r.FontAscent() | |
| 354 | + | _ = r.FontDescent() | |
| 355 | + | _ = r.CharInfosLen() | |
| 356 | + | { | |
| 357 | + | l0 := r.Properties() | |
| 358 | + | for i := 0; i < l0.Len(); i++ { | |
| 359 | + | _ = l0.At(i) | |
| 360 | + | } | |
| 361 | + | } | |
| 362 | + | { | |
| 363 | + | l0 := r.CharInfos() | |
| 364 | + | for i := 0; i < l0.Len(); i++ { | |
| 365 | + | _ = l0.At(i) | |
| 366 | + | } | |
| 367 | + | } | |
| 368 | + | }) | |
| 369 | + | } | |
| 370 | + | ||
| 371 | + | func FuzzParseQueryTextExtentsReply(f *testing.F) { | |
| 372 | + | f.Add(make([]byte, 32)) | |
| 373 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 374 | + | r, ok := ParseQueryTextExtentsReply(raw) | |
| 375 | + | if !ok { | |
| 376 | + | if len(raw) >= 32 { | |
| 377 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 378 | + | } | |
| 379 | + | return | |
| 380 | + | } | |
| 381 | + | if len(r.Raw()) != len(raw) { | |
| 382 | + | t.Fatal("Raw must return the parsed bytes") | |
| 383 | + | } | |
| 384 | + | _ = r.DrawDirection() | |
| 385 | + | _ = r.FontAscent() | |
| 386 | + | _ = r.FontDescent() | |
| 387 | + | _ = r.OverallAscent() | |
| 388 | + | _ = r.OverallDescent() | |
| 389 | + | _ = r.OverallWidth() | |
| 390 | + | _ = r.OverallLeft() | |
| 391 | + | _ = r.OverallRight() | |
| 392 | + | }) | |
| 393 | + | } | |
| 394 | + | ||
| 395 | + | func FuzzParseListFontsReply(f *testing.F) { | |
| 396 | + | f.Add(make([]byte, 32)) | |
| 397 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 398 | + | r, ok := ParseListFontsReply(raw) | |
| 399 | + | if !ok { | |
| 400 | + | return | |
| 401 | + | } | |
| 402 | + | if len(r.Raw()) != len(raw) { | |
| 403 | + | t.Fatal("Raw must return the parsed bytes") | |
| 404 | + | } | |
| 405 | + | _ = r.NamesLen() | |
| 406 | + | { | |
| 407 | + | it0 := r.Names() | |
| 408 | + | for it0.Next() { | |
| 409 | + | _ = it0.Value().NameLen() | |
| 410 | + | _ = len(it0.Value().Name()) | |
| 411 | + | } | |
| 412 | + | if it0.Err() { | |
| 413 | + | t.Fatal("iterator error after successful Parse") | |
| 414 | + | } | |
| 415 | + | } | |
| 416 | + | }) | |
| 417 | + | } | |
| 418 | + | ||
| 419 | + | func FuzzParseListFontsWithInfoReply(f *testing.F) { | |
| 420 | + | f.Add(make([]byte, 60)) | |
| 421 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 422 | + | r, ok := ParseListFontsWithInfoReply(raw) | |
| 423 | + | if !ok { | |
| 424 | + | return | |
| 425 | + | } | |
| 426 | + | if len(r.Raw()) != len(raw) { | |
| 427 | + | t.Fatal("Raw must return the parsed bytes") | |
| 428 | + | } | |
| 429 | + | _ = r.NameLen() | |
| 430 | + | _ = r.MinBounds() | |
| 431 | + | _ = r.MaxBounds() | |
| 432 | + | _ = r.MinCharOrByte2() | |
| 433 | + | _ = r.MaxCharOrByte2() | |
| 434 | + | _ = r.DefaultChar() | |
| 435 | + | _ = r.PropertiesLen() | |
| 436 | + | _ = r.DrawDirection() | |
| 437 | + | _ = r.MinByte1() | |
| 438 | + | _ = r.MaxByte1() | |
| 439 | + | _ = r.AllCharsExist() | |
| 440 | + | _ = r.FontAscent() | |
| 441 | + | _ = r.FontDescent() | |
| 442 | + | _ = r.RepliesHint() | |
| 443 | + | { | |
| 444 | + | l0 := r.Properties() | |
| 445 | + | for i := 0; i < l0.Len(); i++ { | |
| 446 | + | _ = l0.At(i) | |
| 447 | + | } | |
| 448 | + | } | |
| 449 | + | _ = len(r.Name()) | |
| 450 | + | }) | |
| 451 | + | } | |
| 452 | + | ||
| 453 | + | func FuzzParseGetFontPathReply(f *testing.F) { | |
| 454 | + | f.Add(make([]byte, 32)) | |
| 455 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 456 | + | r, ok := ParseGetFontPathReply(raw) | |
| 457 | + | if !ok { | |
| 458 | + | return | |
| 459 | + | } | |
| 460 | + | if len(r.Raw()) != len(raw) { | |
| 461 | + | t.Fatal("Raw must return the parsed bytes") | |
| 462 | + | } | |
| 463 | + | _ = r.PathLen() | |
| 464 | + | { | |
| 465 | + | it0 := r.Path() | |
| 466 | + | for it0.Next() { | |
| 467 | + | _ = it0.Value().NameLen() | |
| 468 | + | _ = len(it0.Value().Name()) | |
| 469 | + | } | |
| 470 | + | if it0.Err() { | |
| 471 | + | t.Fatal("iterator error after successful Parse") | |
| 472 | + | } | |
| 473 | + | } | |
| 474 | + | }) | |
| 475 | + | } | |
| 476 | + | ||
| 477 | + | func FuzzParseGetImageReply(f *testing.F) { | |
| 478 | + | f.Add(make([]byte, 32)) | |
| 479 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 480 | + | r, ok := ParseGetImageReply(raw) | |
| 481 | + | if !ok { | |
| 482 | + | return | |
| 483 | + | } | |
| 484 | + | if len(r.Raw()) != len(raw) { | |
| 485 | + | t.Fatal("Raw must return the parsed bytes") | |
| 486 | + | } | |
| 487 | + | _ = r.Depth() | |
| 488 | + | _ = r.Visual() | |
| 489 | + | _ = len(r.Data()) | |
| 490 | + | }) | |
| 491 | + | } | |
| 492 | + | ||
| 493 | + | func FuzzParseListInstalledColormapsReply(f *testing.F) { | |
| 494 | + | f.Add(make([]byte, 32)) | |
| 495 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 496 | + | r, ok := ParseListInstalledColormapsReply(raw) | |
| 497 | + | if !ok { | |
| 498 | + | return | |
| 499 | + | } | |
| 500 | + | if len(r.Raw()) != len(raw) { | |
| 501 | + | t.Fatal("Raw must return the parsed bytes") | |
| 502 | + | } | |
| 503 | + | _ = r.CmapsLen() | |
| 504 | + | { | |
| 505 | + | l0 := r.Cmaps() | |
| 506 | + | for i := 0; i < l0.Len(); i++ { | |
| 507 | + | _ = l0.At(i) | |
| 508 | + | } | |
| 509 | + | } | |
| 510 | + | }) | |
| 511 | + | } | |
| 512 | + | ||
| 513 | + | func FuzzParseAllocColorReply(f *testing.F) { | |
| 514 | + | f.Add(make([]byte, 32)) | |
| 515 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 516 | + | r, ok := ParseAllocColorReply(raw) | |
| 517 | + | if !ok { | |
| 518 | + | if len(raw) >= 32 { | |
| 519 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 520 | + | } | |
| 521 | + | return | |
| 522 | + | } | |
| 523 | + | if len(r.Raw()) != len(raw) { | |
| 524 | + | t.Fatal("Raw must return the parsed bytes") | |
| 525 | + | } | |
| 526 | + | _ = r.Red() | |
| 527 | + | _ = r.Green() | |
| 528 | + | _ = r.Blue() | |
| 529 | + | _ = r.Pixel() | |
| 530 | + | }) | |
| 531 | + | } | |
| 532 | + | ||
| 533 | + | func FuzzParseAllocNamedColorReply(f *testing.F) { | |
| 534 | + | f.Add(make([]byte, 32)) | |
| 535 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 536 | + | r, ok := ParseAllocNamedColorReply(raw) | |
| 537 | + | if !ok { | |
| 538 | + | if len(raw) >= 32 { | |
| 539 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 540 | + | } | |
| 541 | + | return | |
| 542 | + | } | |
| 543 | + | if len(r.Raw()) != len(raw) { | |
| 544 | + | t.Fatal("Raw must return the parsed bytes") | |
| 545 | + | } | |
| 546 | + | _ = r.Pixel() | |
| 547 | + | _ = r.ExactRed() | |
| 548 | + | _ = r.ExactGreen() | |
| 549 | + | _ = r.ExactBlue() | |
| 550 | + | _ = r.VisualRed() | |
| 551 | + | _ = r.VisualGreen() | |
| 552 | + | _ = r.VisualBlue() | |
| 553 | + | }) | |
| 554 | + | } | |
| 555 | + | ||
| 556 | + | func FuzzParseAllocColorCellsReply(f *testing.F) { | |
| 557 | + | f.Add(make([]byte, 32)) | |
| 558 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 559 | + | r, ok := ParseAllocColorCellsReply(raw) | |
| 560 | + | if !ok { | |
| 561 | + | return | |
| 562 | + | } | |
| 563 | + | if len(r.Raw()) != len(raw) { | |
| 564 | + | t.Fatal("Raw must return the parsed bytes") | |
| 565 | + | } | |
| 566 | + | _ = r.PixelsLen() | |
| 567 | + | _ = r.MasksLen() | |
| 568 | + | { | |
| 569 | + | l0 := r.Pixels() | |
| 570 | + | for i := 0; i < l0.Len(); i++ { | |
| 571 | + | _ = l0.At(i) | |
| 572 | + | } | |
| 573 | + | } | |
| 574 | + | { | |
| 575 | + | l0 := r.Masks() | |
| 576 | + | for i := 0; i < l0.Len(); i++ { | |
| 577 | + | _ = l0.At(i) | |
| 578 | + | } | |
| 579 | + | } | |
| 580 | + | }) | |
| 581 | + | } | |
| 582 | + | ||
| 583 | + | func FuzzParseAllocColorPlanesReply(f *testing.F) { | |
| 584 | + | f.Add(make([]byte, 32)) | |
| 585 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 586 | + | r, ok := ParseAllocColorPlanesReply(raw) | |
| 587 | + | if !ok { | |
| 588 | + | return | |
| 589 | + | } | |
| 590 | + | if len(r.Raw()) != len(raw) { | |
| 591 | + | t.Fatal("Raw must return the parsed bytes") | |
| 592 | + | } | |
| 593 | + | _ = r.PixelsLen() | |
| 594 | + | _ = r.RedMask() | |
| 595 | + | _ = r.GreenMask() | |
| 596 | + | _ = r.BlueMask() | |
| 597 | + | { | |
| 598 | + | l0 := r.Pixels() | |
| 599 | + | for i := 0; i < l0.Len(); i++ { | |
| 600 | + | _ = l0.At(i) | |
| 601 | + | } | |
| 602 | + | } | |
| 603 | + | }) | |
| 604 | + | } | |
| 605 | + | ||
| 606 | + | func FuzzParseQueryColorsReply(f *testing.F) { | |
| 607 | + | f.Add(make([]byte, 32)) | |
| 608 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 609 | + | r, ok := ParseQueryColorsReply(raw) | |
| 610 | + | if !ok { | |
| 611 | + | return | |
| 612 | + | } | |
| 613 | + | if len(r.Raw()) != len(raw) { | |
| 614 | + | t.Fatal("Raw must return the parsed bytes") | |
| 615 | + | } | |
| 616 | + | _ = r.ColorsLen() | |
| 617 | + | { | |
| 618 | + | l0 := r.Colors() | |
| 619 | + | for i := 0; i < l0.Len(); i++ { | |
| 620 | + | _ = l0.At(i) | |
| 621 | + | } | |
| 622 | + | } | |
| 623 | + | }) | |
| 624 | + | } | |
| 625 | + | ||
| 626 | + | func FuzzParseLookupColorReply(f *testing.F) { | |
| 627 | + | f.Add(make([]byte, 32)) | |
| 628 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 629 | + | r, ok := ParseLookupColorReply(raw) | |
| 630 | + | if !ok { | |
| 631 | + | if len(raw) >= 32 { | |
| 632 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 633 | + | } | |
| 634 | + | return | |
| 635 | + | } | |
| 636 | + | if len(r.Raw()) != len(raw) { | |
| 637 | + | t.Fatal("Raw must return the parsed bytes") | |
| 638 | + | } | |
| 639 | + | _ = r.ExactRed() | |
| 640 | + | _ = r.ExactGreen() | |
| 641 | + | _ = r.ExactBlue() | |
| 642 | + | _ = r.VisualRed() | |
| 643 | + | _ = r.VisualGreen() | |
| 644 | + | _ = r.VisualBlue() | |
| 645 | + | }) | |
| 646 | + | } | |
| 647 | + | ||
| 648 | + | func FuzzParseQueryBestSizeReply(f *testing.F) { | |
| 649 | + | f.Add(make([]byte, 32)) | |
| 650 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 651 | + | r, ok := ParseQueryBestSizeReply(raw) | |
| 652 | + | if !ok { | |
| 653 | + | if len(raw) >= 32 { | |
| 654 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 655 | + | } | |
| 656 | + | return | |
| 657 | + | } | |
| 658 | + | if len(r.Raw()) != len(raw) { | |
| 659 | + | t.Fatal("Raw must return the parsed bytes") | |
| 660 | + | } | |
| 661 | + | _ = r.Width() | |
| 662 | + | _ = r.Height() | |
| 663 | + | }) | |
| 664 | + | } | |
| 665 | + | ||
| 666 | + | func FuzzParseQueryExtensionReply(f *testing.F) { | |
| 667 | + | f.Add(make([]byte, 32)) | |
| 668 | + | if raw, err := xtest.LoadHex("../testdata/golden/xproto/QueryExtension.reply.hex"); err != nil { | |
| 669 | + | f.Fatal(err) | |
| 670 | + | } else { | |
| 671 | + | f.Add(raw) | |
| 672 | + | } | |
| 673 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 674 | + | r, ok := ParseQueryExtensionReply(raw) | |
| 675 | + | if !ok { | |
| 676 | + | if len(raw) >= 32 { | |
| 677 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 678 | + | } | |
| 679 | + | return | |
| 680 | + | } | |
| 681 | + | if len(r.Raw()) != len(raw) { | |
| 682 | + | t.Fatal("Raw must return the parsed bytes") | |
| 683 | + | } | |
| 684 | + | _ = r.Present() | |
| 685 | + | _ = r.MajorOpcode() | |
| 686 | + | _ = r.FirstEvent() | |
| 687 | + | _ = r.FirstError() | |
| 688 | + | }) | |
| 689 | + | } | |
| 690 | + | ||
| 691 | + | func FuzzParseListExtensionsReply(f *testing.F) { | |
| 692 | + | f.Add(make([]byte, 32)) | |
| 693 | + | if raw, err := xtest.LoadHex("../testdata/golden/xproto/ListExtensions.reply.hex"); err != nil { | |
| 694 | + | f.Fatal(err) | |
| 695 | + | } else { | |
| 696 | + | f.Add(raw) | |
| 697 | + | } | |
| 698 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 699 | + | r, ok := ParseListExtensionsReply(raw) | |
| 700 | + | if !ok { | |
| 701 | + | return | |
| 702 | + | } | |
| 703 | + | if len(r.Raw()) != len(raw) { | |
| 704 | + | t.Fatal("Raw must return the parsed bytes") | |
| 705 | + | } | |
| 706 | + | _ = r.NamesLen() | |
| 707 | + | { | |
| 708 | + | it0 := r.Names() | |
| 709 | + | for it0.Next() { | |
| 710 | + | _ = it0.Value().NameLen() | |
| 711 | + | _ = len(it0.Value().Name()) | |
| 712 | + | } | |
| 713 | + | if it0.Err() { | |
| 714 | + | t.Fatal("iterator error after successful Parse") | |
| 715 | + | } | |
| 716 | + | } | |
| 717 | + | }) | |
| 718 | + | } | |
| 719 | + | ||
| 720 | + | func FuzzParseGetKeyboardMappingReply(f *testing.F) { | |
| 721 | + | f.Add(make([]byte, 32)) | |
| 722 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 723 | + | r, ok := ParseGetKeyboardMappingReply(raw) | |
| 724 | + | if !ok { | |
| 725 | + | return | |
| 726 | + | } | |
| 727 | + | if len(r.Raw()) != len(raw) { | |
| 728 | + | t.Fatal("Raw must return the parsed bytes") | |
| 729 | + | } | |
| 730 | + | _ = r.KeysymsPerKeycode() | |
| 731 | + | { | |
| 732 | + | l0 := r.Keysyms() | |
| 733 | + | for i := 0; i < l0.Len(); i++ { | |
| 734 | + | _ = l0.At(i) | |
| 735 | + | } | |
| 736 | + | } | |
| 737 | + | }) | |
| 738 | + | } | |
| 739 | + | ||
| 740 | + | func FuzzParseGetKeyboardControlReply(f *testing.F) { | |
| 741 | + | f.Add(make([]byte, 52)) | |
| 742 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 743 | + | r, ok := ParseGetKeyboardControlReply(raw) | |
| 744 | + | if !ok { | |
| 745 | + | if len(raw) >= 52 { | |
| 746 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 747 | + | } | |
| 748 | + | return | |
| 749 | + | } | |
| 750 | + | if len(r.Raw()) != len(raw) { | |
| 751 | + | t.Fatal("Raw must return the parsed bytes") | |
| 752 | + | } | |
| 753 | + | _ = r.GlobalAutoRepeat() | |
| 754 | + | _ = r.LedMask() | |
| 755 | + | _ = r.KeyClickPercent() | |
| 756 | + | _ = r.BellPercent() | |
| 757 | + | _ = r.BellPitch() | |
| 758 | + | _ = r.BellDuration() | |
| 759 | + | _ = len(r.AutoRepeats()) | |
| 760 | + | }) | |
| 761 | + | } | |
| 762 | + | ||
| 763 | + | func FuzzParseGetPointerControlReply(f *testing.F) { | |
| 764 | + | f.Add(make([]byte, 32)) | |
| 765 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 766 | + | r, ok := ParseGetPointerControlReply(raw) | |
| 767 | + | if !ok { | |
| 768 | + | if len(raw) >= 32 { | |
| 769 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 770 | + | } | |
| 771 | + | return | |
| 772 | + | } | |
| 773 | + | if len(r.Raw()) != len(raw) { | |
| 774 | + | t.Fatal("Raw must return the parsed bytes") | |
| 775 | + | } | |
| 776 | + | _ = r.AccelerationNumerator() | |
| 777 | + | _ = r.AccelerationDenominator() | |
| 778 | + | _ = r.Threshold() | |
| 779 | + | }) | |
| 780 | + | } | |
| 781 | + | ||
| 782 | + | func FuzzParseGetScreenSaverReply(f *testing.F) { | |
| 783 | + | f.Add(make([]byte, 32)) | |
| 784 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 785 | + | r, ok := ParseGetScreenSaverReply(raw) | |
| 786 | + | if !ok { | |
| 787 | + | if len(raw) >= 32 { | |
| 788 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 789 | + | } | |
| 790 | + | return | |
| 791 | + | } | |
| 792 | + | if len(r.Raw()) != len(raw) { | |
| 793 | + | t.Fatal("Raw must return the parsed bytes") | |
| 794 | + | } | |
| 795 | + | _ = r.Timeout() | |
| 796 | + | _ = r.Interval() | |
| 797 | + | _ = r.PreferBlanking() | |
| 798 | + | _ = r.AllowExposures() | |
| 799 | + | }) | |
| 800 | + | } | |
| 801 | + | ||
| 802 | + | func FuzzParseListHostsReply(f *testing.F) { | |
| 803 | + | f.Add(make([]byte, 32)) | |
| 804 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 805 | + | r, ok := ParseListHostsReply(raw) | |
| 806 | + | if !ok { | |
| 807 | + | return | |
| 808 | + | } | |
| 809 | + | if len(r.Raw()) != len(raw) { | |
| 810 | + | t.Fatal("Raw must return the parsed bytes") | |
| 811 | + | } | |
| 812 | + | _ = r.Mode() | |
| 813 | + | _ = r.HostsLen() | |
| 814 | + | { | |
| 815 | + | it0 := r.Hosts() | |
| 816 | + | for it0.Next() { | |
| 817 | + | _ = it0.Value().Family() | |
| 818 | + | _ = it0.Value().AddressLen() | |
| 819 | + | _ = len(it0.Value().Address()) | |
| 820 | + | } | |
| 821 | + | if it0.Err() { | |
| 822 | + | t.Fatal("iterator error after successful Parse") | |
| 823 | + | } | |
| 824 | + | } | |
| 825 | + | }) | |
| 826 | + | } | |
| 827 | + | ||
| 828 | + | func FuzzParseSetPointerMappingReply(f *testing.F) { | |
| 829 | + | f.Add(make([]byte, 32)) | |
| 830 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 831 | + | r, ok := ParseSetPointerMappingReply(raw) | |
| 832 | + | if !ok { | |
| 833 | + | if len(raw) >= 32 { | |
| 834 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 835 | + | } | |
| 836 | + | return | |
| 837 | + | } | |
| 838 | + | if len(r.Raw()) != len(raw) { | |
| 839 | + | t.Fatal("Raw must return the parsed bytes") | |
| 840 | + | } | |
| 841 | + | _ = r.Status() | |
| 842 | + | }) | |
| 843 | + | } | |
| 844 | + | ||
| 845 | + | func FuzzParseGetPointerMappingReply(f *testing.F) { | |
| 846 | + | f.Add(make([]byte, 32)) | |
| 847 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 848 | + | r, ok := ParseGetPointerMappingReply(raw) | |
| 849 | + | if !ok { | |
| 850 | + | return | |
| 851 | + | } | |
| 852 | + | if len(r.Raw()) != len(raw) { | |
| 853 | + | t.Fatal("Raw must return the parsed bytes") | |
| 854 | + | } | |
| 855 | + | _ = r.MapLen() | |
| 856 | + | _ = len(r.Map()) | |
| 857 | + | }) | |
| 858 | + | } | |
| 859 | + | ||
| 860 | + | func FuzzParseSetModifierMappingReply(f *testing.F) { | |
| 861 | + | f.Add(make([]byte, 32)) | |
| 862 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 863 | + | r, ok := ParseSetModifierMappingReply(raw) | |
| 864 | + | if !ok { | |
| 865 | + | if len(raw) >= 32 { | |
| 866 | + | t.Fatal("rejected a complete fixed-size reply") | |
| 867 | + | } | |
| 868 | + | return | |
| 869 | + | } | |
| 870 | + | if len(r.Raw()) != len(raw) { | |
| 871 | + | t.Fatal("Raw must return the parsed bytes") | |
| 872 | + | } | |
| 873 | + | _ = r.Status() | |
| 874 | + | }) | |
| 875 | + | } | |
| 876 | + | ||
| 877 | + | func FuzzParseGetModifierMappingReply(f *testing.F) { | |
| 878 | + | f.Add(make([]byte, 32)) | |
| 879 | + | f.Fuzz(func(t *testing.T, raw []byte) { | |
| 880 | + | r, ok := ParseGetModifierMappingReply(raw) | |
| 881 | + | if !ok { | |
| 882 | + | return | |
| 883 | + | } | |
| 884 | + | if len(r.Raw()) != len(raw) { | |
| 885 | + | t.Fatal("Raw must return the parsed bytes") | |
| 886 | + | } | |
| 887 | + | _ = r.KeycodesPerModifier() | |
| 888 | + | { | |
| 889 | + | l0 := r.Keycodes() | |
| 890 | + | for i := 0; i < l0.Len(); i++ { | |
| 891 | + | _ = l0.At(i) | |
| 892 | + | } | |
| 893 | + | } | |
| 894 | + | }) | |
| 895 | + | } | |
A xproto/replies_generated.go +1964 -0
| @@ -0,0 +1,1964 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xproto | |
| 3 | + | ||
| 4 | + | import "encoding/binary" | |
| 5 | + | ||
| 6 | + | // GetWindowAttributesReply is a zero-copy view over a GetWindowAttributes reply; offsets count from reply byte 0. | |
| 7 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 8 | + | type GetWindowAttributesReply struct{ raw []byte } | |
| 9 | + | ||
| 10 | + | // ParseGetWindowAttributesReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 11 | + | func ParseGetWindowAttributesReply(raw []byte) (GetWindowAttributesReply, bool) { | |
| 12 | + | if len(raw) < 44 { | |
| 13 | + | return GetWindowAttributesReply{}, false | |
| 14 | + | } | |
| 15 | + | r := GetWindowAttributesReply{raw: raw} | |
| 16 | + | return r, true | |
| 17 | + | } | |
| 18 | + | func (r GetWindowAttributesReply) Raw() []byte { return r.raw } | |
| 19 | + | func (r GetWindowAttributesReply) BackingStore() BackingStore { return BackingStore(r.raw[1:][0]) } | |
| 20 | + | func (r GetWindowAttributesReply) Visual() Visualid { | |
| 21 | + | return Visualid(binary.LittleEndian.Uint32(r.raw[8:])) | |
| 22 | + | } | |
| 23 | + | func (r GetWindowAttributesReply) Class() WindowClass { | |
| 24 | + | return WindowClass(binary.LittleEndian.Uint16(r.raw[12:])) | |
| 25 | + | } | |
| 26 | + | func (r GetWindowAttributesReply) BitGravity() Gravity { return Gravity(r.raw[14:][0]) } | |
| 27 | + | func (r GetWindowAttributesReply) WinGravity() Gravity { return Gravity(r.raw[15:][0]) } | |
| 28 | + | func (r GetWindowAttributesReply) BackingPlanes() uint32 { | |
| 29 | + | return uint32(binary.LittleEndian.Uint32(r.raw[16:])) | |
| 30 | + | } | |
| 31 | + | func (r GetWindowAttributesReply) BackingPixel() uint32 { | |
| 32 | + | return uint32(binary.LittleEndian.Uint32(r.raw[20:])) | |
| 33 | + | } | |
| 34 | + | func (r GetWindowAttributesReply) SaveUnder() bool { return (r.raw[24:][0] != 0) } | |
| 35 | + | func (r GetWindowAttributesReply) MapIsInstalled() bool { return (r.raw[25:][0] != 0) } | |
| 36 | + | func (r GetWindowAttributesReply) MapState() MapState { return MapState(r.raw[26:][0]) } | |
| 37 | + | func (r GetWindowAttributesReply) OverrideRedirect() bool { return (r.raw[27:][0] != 0) } | |
| 38 | + | func (r GetWindowAttributesReply) Colormap() Colormap { | |
| 39 | + | return Colormap(binary.LittleEndian.Uint32(r.raw[28:])) | |
| 40 | + | } | |
| 41 | + | func (r GetWindowAttributesReply) AllEventMasks() EventMask { | |
| 42 | + | return EventMask(binary.LittleEndian.Uint32(r.raw[32:])) | |
| 43 | + | } | |
| 44 | + | func (r GetWindowAttributesReply) YourEventMask() EventMask { | |
| 45 | + | return EventMask(binary.LittleEndian.Uint32(r.raw[36:])) | |
| 46 | + | } | |
| 47 | + | func (r GetWindowAttributesReply) DoNotPropagateMask() EventMask { | |
| 48 | + | return EventMask(binary.LittleEndian.Uint16(r.raw[40:])) | |
| 49 | + | } | |
| 50 | + | ||
| 51 | + | // GetGeometryReply is a zero-copy view over a GetGeometry reply; offsets count from reply byte 0. | |
| 52 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 53 | + | type GetGeometryReply struct{ raw []byte } | |
| 54 | + | ||
| 55 | + | // ParseGetGeometryReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 56 | + | func ParseGetGeometryReply(raw []byte) (GetGeometryReply, bool) { | |
| 57 | + | if len(raw) < 32 { | |
| 58 | + | return GetGeometryReply{}, false | |
| 59 | + | } | |
| 60 | + | r := GetGeometryReply{raw: raw} | |
| 61 | + | return r, true | |
| 62 | + | } | |
| 63 | + | func (r GetGeometryReply) Raw() []byte { return r.raw } | |
| 64 | + | func (r GetGeometryReply) Depth() uint8 { return uint8(r.raw[1:][0]) } | |
| 65 | + | func (r GetGeometryReply) Root() Window { return Window(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 66 | + | func (r GetGeometryReply) X() int16 { return int16(binary.LittleEndian.Uint16(r.raw[12:])) } | |
| 67 | + | func (r GetGeometryReply) Y() int16 { return int16(binary.LittleEndian.Uint16(r.raw[14:])) } | |
| 68 | + | func (r GetGeometryReply) Width() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[16:])) } | |
| 69 | + | func (r GetGeometryReply) Height() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[18:])) } | |
| 70 | + | func (r GetGeometryReply) BorderWidth() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[20:])) } | |
| 71 | + | ||
| 72 | + | // QueryTreeReply is a zero-copy view over a QueryTree reply; offsets count from reply byte 0. | |
| 73 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 74 | + | type QueryTreeReply struct{ raw []byte } | |
| 75 | + | ||
| 76 | + | // ParseQueryTreeReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 77 | + | func ParseQueryTreeReply(raw []byte) (QueryTreeReply, bool) { | |
| 78 | + | if len(raw) < 32 { | |
| 79 | + | return QueryTreeReply{}, false | |
| 80 | + | } | |
| 81 | + | r := QueryTreeReply{raw: raw} | |
| 82 | + | off := 32 | |
| 83 | + | { | |
| 84 | + | n := int(r.ChildrenLen()) | |
| 85 | + | if n < 0 || n > len(r.raw) { | |
| 86 | + | return QueryTreeReply{}, false | |
| 87 | + | } | |
| 88 | + | off += n * 4 | |
| 89 | + | } | |
| 90 | + | if off > len(r.raw) { | |
| 91 | + | return QueryTreeReply{}, false | |
| 92 | + | } | |
| 93 | + | if off > len(r.raw) { | |
| 94 | + | return QueryTreeReply{}, false | |
| 95 | + | } | |
| 96 | + | return r, true | |
| 97 | + | } | |
| 98 | + | func (r QueryTreeReply) Raw() []byte { return r.raw } | |
| 99 | + | func (r QueryTreeReply) Root() Window { return Window(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 100 | + | func (r QueryTreeReply) Parent() Window { return Window(binary.LittleEndian.Uint32(r.raw[12:])) } | |
| 101 | + | func (r QueryTreeReply) ChildrenLen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[16:])) } | |
| 102 | + | func (r QueryTreeReply) Children() WindowList { | |
| 103 | + | off := 32 | |
| 104 | + | end := off + (int(r.ChildrenLen()))*4 | |
| 105 | + | return WindowList{b: r.raw[off:end:end]} | |
| 106 | + | } | |
| 107 | + | ||
| 108 | + | // InternAtomReply is a zero-copy view over a InternAtom reply; offsets count from reply byte 0. | |
| 109 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 110 | + | type InternAtomReply struct{ raw []byte } | |
| 111 | + | ||
| 112 | + | // ParseInternAtomReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 113 | + | func ParseInternAtomReply(raw []byte) (InternAtomReply, bool) { | |
| 114 | + | if len(raw) < 32 { | |
| 115 | + | return InternAtomReply{}, false | |
| 116 | + | } | |
| 117 | + | r := InternAtomReply{raw: raw} | |
| 118 | + | return r, true | |
| 119 | + | } | |
| 120 | + | func (r InternAtomReply) Raw() []byte { return r.raw } | |
| 121 | + | func (r InternAtomReply) Atom() Atom { return Atom(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 122 | + | ||
| 123 | + | // GetAtomNameReply is a zero-copy view over a GetAtomName reply; offsets count from reply byte 0. | |
| 124 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 125 | + | type GetAtomNameReply struct{ raw []byte } | |
| 126 | + | ||
| 127 | + | // ParseGetAtomNameReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 128 | + | func ParseGetAtomNameReply(raw []byte) (GetAtomNameReply, bool) { | |
| 129 | + | if len(raw) < 32 { | |
| 130 | + | return GetAtomNameReply{}, false | |
| 131 | + | } | |
| 132 | + | r := GetAtomNameReply{raw: raw} | |
| 133 | + | off := 32 | |
| 134 | + | { | |
| 135 | + | n := int(r.NameLen()) | |
| 136 | + | if n < 0 || n > len(r.raw) { | |
| 137 | + | return GetAtomNameReply{}, false | |
| 138 | + | } | |
| 139 | + | off += n * 1 | |
| 140 | + | } | |
| 141 | + | if off > len(r.raw) { | |
| 142 | + | return GetAtomNameReply{}, false | |
| 143 | + | } | |
| 144 | + | if off > len(r.raw) { | |
| 145 | + | return GetAtomNameReply{}, false | |
| 146 | + | } | |
| 147 | + | return r, true | |
| 148 | + | } | |
| 149 | + | func (r GetAtomNameReply) Raw() []byte { return r.raw } | |
| 150 | + | func (r GetAtomNameReply) NameLen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 151 | + | func (r GetAtomNameReply) Name() []byte { | |
| 152 | + | off := 32 | |
| 153 | + | end := off + int(r.NameLen()) | |
| 154 | + | return r.raw[off:end:end] | |
| 155 | + | } | |
| 156 | + | ||
| 157 | + | // GetPropertyReply is a zero-copy view over a GetProperty reply; offsets count from reply byte 0. | |
| 158 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 159 | + | type GetPropertyReply struct{ raw []byte } | |
| 160 | + | ||
| 161 | + | // ParseGetPropertyReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 162 | + | func ParseGetPropertyReply(raw []byte) (GetPropertyReply, bool) { | |
| 163 | + | if len(raw) < 32 { | |
| 164 | + | return GetPropertyReply{}, false | |
| 165 | + | } | |
| 166 | + | r := GetPropertyReply{raw: raw} | |
| 167 | + | off := 32 | |
| 168 | + | { | |
| 169 | + | n := (int(r.ValueLen()) * (int(r.Format()) / 8)) | |
| 170 | + | if n < 0 || n > len(r.raw) { | |
| 171 | + | return GetPropertyReply{}, false | |
| 172 | + | } | |
| 173 | + | off += n * 1 | |
| 174 | + | } | |
| 175 | + | if off > len(r.raw) { | |
| 176 | + | return GetPropertyReply{}, false | |
| 177 | + | } | |
| 178 | + | if off > len(r.raw) { | |
| 179 | + | return GetPropertyReply{}, false | |
| 180 | + | } | |
| 181 | + | return r, true | |
| 182 | + | } | |
| 183 | + | func (r GetPropertyReply) Raw() []byte { return r.raw } | |
| 184 | + | func (r GetPropertyReply) Format() uint8 { return uint8(r.raw[1:][0]) } | |
| 185 | + | func (r GetPropertyReply) Type() Atom { return Atom(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 186 | + | func (r GetPropertyReply) BytesAfter() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[12:])) } | |
| 187 | + | func (r GetPropertyReply) ValueLen() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[16:])) } | |
| 188 | + | func (r GetPropertyReply) Value() []byte { | |
| 189 | + | off := 32 | |
| 190 | + | end := off + (int(r.ValueLen()) * (int(r.Format()) / 8)) | |
| 191 | + | return r.raw[off:end:end] | |
| 192 | + | } | |
| 193 | + | ||
| 194 | + | // ListPropertiesReply is a zero-copy view over a ListProperties reply; offsets count from reply byte 0. | |
| 195 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 196 | + | type ListPropertiesReply struct{ raw []byte } | |
| 197 | + | ||
| 198 | + | // ParseListPropertiesReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 199 | + | func ParseListPropertiesReply(raw []byte) (ListPropertiesReply, bool) { | |
| 200 | + | if len(raw) < 32 { | |
| 201 | + | return ListPropertiesReply{}, false | |
| 202 | + | } | |
| 203 | + | r := ListPropertiesReply{raw: raw} | |
| 204 | + | off := 32 | |
| 205 | + | { | |
| 206 | + | n := int(r.AtomsLen()) | |
| 207 | + | if n < 0 || n > len(r.raw) { | |
| 208 | + | return ListPropertiesReply{}, false | |
| 209 | + | } | |
| 210 | + | off += n * 4 | |
| 211 | + | } | |
| 212 | + | if off > len(r.raw) { | |
| 213 | + | return ListPropertiesReply{}, false | |
| 214 | + | } | |
| 215 | + | if off > len(r.raw) { | |
| 216 | + | return ListPropertiesReply{}, false | |
| 217 | + | } | |
| 218 | + | return r, true | |
| 219 | + | } | |
| 220 | + | func (r ListPropertiesReply) Raw() []byte { return r.raw } | |
| 221 | + | func (r ListPropertiesReply) AtomsLen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 222 | + | func (r ListPropertiesReply) Atoms() AtomList { | |
| 223 | + | off := 32 | |
| 224 | + | end := off + (int(r.AtomsLen()))*4 | |
| 225 | + | return AtomList{b: r.raw[off:end:end]} | |
| 226 | + | } | |
| 227 | + | ||
| 228 | + | // GetSelectionOwnerReply is a zero-copy view over a GetSelectionOwner reply; offsets count from reply byte 0. | |
| 229 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 230 | + | type GetSelectionOwnerReply struct{ raw []byte } | |
| 231 | + | ||
| 232 | + | // ParseGetSelectionOwnerReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 233 | + | func ParseGetSelectionOwnerReply(raw []byte) (GetSelectionOwnerReply, bool) { | |
| 234 | + | if len(raw) < 32 { | |
| 235 | + | return GetSelectionOwnerReply{}, false | |
| 236 | + | } | |
| 237 | + | r := GetSelectionOwnerReply{raw: raw} | |
| 238 | + | return r, true | |
| 239 | + | } | |
| 240 | + | func (r GetSelectionOwnerReply) Raw() []byte { return r.raw } | |
| 241 | + | func (r GetSelectionOwnerReply) Owner() Window { return Window(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 242 | + | ||
| 243 | + | // GrabPointerReply is a zero-copy view over a GrabPointer reply; offsets count from reply byte 0. | |
| 244 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 245 | + | type GrabPointerReply struct{ raw []byte } | |
| 246 | + | ||
| 247 | + | // ParseGrabPointerReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 248 | + | func ParseGrabPointerReply(raw []byte) (GrabPointerReply, bool) { | |
| 249 | + | if len(raw) < 32 { | |
| 250 | + | return GrabPointerReply{}, false | |
| 251 | + | } | |
| 252 | + | r := GrabPointerReply{raw: raw} | |
| 253 | + | return r, true | |
| 254 | + | } | |
| 255 | + | func (r GrabPointerReply) Raw() []byte { return r.raw } | |
| 256 | + | func (r GrabPointerReply) Status() GrabStatus { return GrabStatus(r.raw[1:][0]) } | |
| 257 | + | ||
| 258 | + | // GrabKeyboardReply is a zero-copy view over a GrabKeyboard reply; offsets count from reply byte 0. | |
| 259 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 260 | + | type GrabKeyboardReply struct{ raw []byte } | |
| 261 | + | ||
| 262 | + | // ParseGrabKeyboardReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 263 | + | func ParseGrabKeyboardReply(raw []byte) (GrabKeyboardReply, bool) { | |
| 264 | + | if len(raw) < 32 { | |
| 265 | + | return GrabKeyboardReply{}, false | |
| 266 | + | } | |
| 267 | + | r := GrabKeyboardReply{raw: raw} | |
| 268 | + | return r, true | |
| 269 | + | } | |
| 270 | + | func (r GrabKeyboardReply) Raw() []byte { return r.raw } | |
| 271 | + | func (r GrabKeyboardReply) Status() GrabStatus { return GrabStatus(r.raw[1:][0]) } | |
| 272 | + | ||
| 273 | + | // QueryPointerReply is a zero-copy view over a QueryPointer reply; offsets count from reply byte 0. | |
| 274 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 275 | + | type QueryPointerReply struct{ raw []byte } | |
| 276 | + | ||
| 277 | + | // ParseQueryPointerReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 278 | + | func ParseQueryPointerReply(raw []byte) (QueryPointerReply, bool) { | |
| 279 | + | if len(raw) < 32 { | |
| 280 | + | return QueryPointerReply{}, false | |
| 281 | + | } | |
| 282 | + | r := QueryPointerReply{raw: raw} | |
| 283 | + | return r, true | |
| 284 | + | } | |
| 285 | + | func (r QueryPointerReply) Raw() []byte { return r.raw } | |
| 286 | + | func (r QueryPointerReply) SameScreen() bool { return (r.raw[1:][0] != 0) } | |
| 287 | + | func (r QueryPointerReply) Root() Window { return Window(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 288 | + | func (r QueryPointerReply) Child() Window { return Window(binary.LittleEndian.Uint32(r.raw[12:])) } | |
| 289 | + | func (r QueryPointerReply) RootX() int16 { return int16(binary.LittleEndian.Uint16(r.raw[16:])) } | |
| 290 | + | func (r QueryPointerReply) RootY() int16 { return int16(binary.LittleEndian.Uint16(r.raw[18:])) } | |
| 291 | + | func (r QueryPointerReply) WinX() int16 { return int16(binary.LittleEndian.Uint16(r.raw[20:])) } | |
| 292 | + | func (r QueryPointerReply) WinY() int16 { return int16(binary.LittleEndian.Uint16(r.raw[22:])) } | |
| 293 | + | func (r QueryPointerReply) Mask() KeyButMask { | |
| 294 | + | return KeyButMask(binary.LittleEndian.Uint16(r.raw[24:])) | |
| 295 | + | } | |
| 296 | + | ||
| 297 | + | // GetMotionEventsReply is a zero-copy view over a GetMotionEvents reply; offsets count from reply byte 0. | |
| 298 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 299 | + | type GetMotionEventsReply struct{ raw []byte } | |
| 300 | + | ||
| 301 | + | // ParseGetMotionEventsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 302 | + | func ParseGetMotionEventsReply(raw []byte) (GetMotionEventsReply, bool) { | |
| 303 | + | if len(raw) < 32 { | |
| 304 | + | return GetMotionEventsReply{}, false | |
| 305 | + | } | |
| 306 | + | r := GetMotionEventsReply{raw: raw} | |
| 307 | + | off := 32 | |
| 308 | + | { | |
| 309 | + | n := int(r.EventsLen()) | |
| 310 | + | if n < 0 || n > len(r.raw) { | |
| 311 | + | return GetMotionEventsReply{}, false | |
| 312 | + | } | |
| 313 | + | off += n * 8 | |
| 314 | + | } | |
| 315 | + | if off > len(r.raw) { | |
| 316 | + | return GetMotionEventsReply{}, false | |
| 317 | + | } | |
| 318 | + | if off > len(r.raw) { | |
| 319 | + | return GetMotionEventsReply{}, false | |
| 320 | + | } | |
| 321 | + | return r, true | |
| 322 | + | } | |
| 323 | + | func (r GetMotionEventsReply) Raw() []byte { return r.raw } | |
| 324 | + | func (r GetMotionEventsReply) EventsLen() uint32 { | |
| 325 | + | return uint32(binary.LittleEndian.Uint32(r.raw[8:])) | |
| 326 | + | } | |
| 327 | + | func (r GetMotionEventsReply) Events() TimecoordList { | |
| 328 | + | off := 32 | |
| 329 | + | end := off + (int(r.EventsLen()))*8 | |
| 330 | + | return TimecoordList{b: r.raw[off:end:end]} | |
| 331 | + | } | |
| 332 | + | ||
| 333 | + | // TranslateCoordinatesReply is a zero-copy view over a TranslateCoordinates reply; offsets count from reply byte 0. | |
| 334 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 335 | + | type TranslateCoordinatesReply struct{ raw []byte } | |
| 336 | + | ||
| 337 | + | // ParseTranslateCoordinatesReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 338 | + | func ParseTranslateCoordinatesReply(raw []byte) (TranslateCoordinatesReply, bool) { | |
| 339 | + | if len(raw) < 32 { | |
| 340 | + | return TranslateCoordinatesReply{}, false | |
| 341 | + | } | |
| 342 | + | r := TranslateCoordinatesReply{raw: raw} | |
| 343 | + | return r, true | |
| 344 | + | } | |
| 345 | + | func (r TranslateCoordinatesReply) Raw() []byte { return r.raw } | |
| 346 | + | func (r TranslateCoordinatesReply) SameScreen() bool { return (r.raw[1:][0] != 0) } | |
| 347 | + | func (r TranslateCoordinatesReply) Child() Window { | |
| 348 | + | return Window(binary.LittleEndian.Uint32(r.raw[8:])) | |
| 349 | + | } | |
| 350 | + | func (r TranslateCoordinatesReply) DstX() int16 { return int16(binary.LittleEndian.Uint16(r.raw[12:])) } | |
| 351 | + | func (r TranslateCoordinatesReply) DstY() int16 { return int16(binary.LittleEndian.Uint16(r.raw[14:])) } | |
| 352 | + | ||
| 353 | + | // GetInputFocusReply is a zero-copy view over a GetInputFocus reply; offsets count from reply byte 0. | |
| 354 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 355 | + | type GetInputFocusReply struct{ raw []byte } | |
| 356 | + | ||
| 357 | + | // ParseGetInputFocusReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 358 | + | func ParseGetInputFocusReply(raw []byte) (GetInputFocusReply, bool) { | |
| 359 | + | if len(raw) < 32 { | |
| 360 | + | return GetInputFocusReply{}, false | |
| 361 | + | } | |
| 362 | + | r := GetInputFocusReply{raw: raw} | |
| 363 | + | return r, true | |
| 364 | + | } | |
| 365 | + | func (r GetInputFocusReply) Raw() []byte { return r.raw } | |
| 366 | + | func (r GetInputFocusReply) RevertTo() InputFocus { return InputFocus(r.raw[1:][0]) } | |
| 367 | + | func (r GetInputFocusReply) Focus() Window { return Window(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 368 | + | ||
| 369 | + | // QueryKeymapReply is a zero-copy view over a QueryKeymap reply; offsets count from reply byte 0. | |
| 370 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 371 | + | type QueryKeymapReply struct{ raw []byte } | |
| 372 | + | ||
| 373 | + | // ParseQueryKeymapReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 374 | + | func ParseQueryKeymapReply(raw []byte) (QueryKeymapReply, bool) { | |
| 375 | + | if len(raw) < 40 { | |
| 376 | + | return QueryKeymapReply{}, false | |
| 377 | + | } | |
| 378 | + | r := QueryKeymapReply{raw: raw} | |
| 379 | + | return r, true | |
| 380 | + | } | |
| 381 | + | func (r QueryKeymapReply) Raw() []byte { return r.raw } | |
| 382 | + | func (r QueryKeymapReply) Keys() []byte { off := 8; end := off + 32; return r.raw[off:end:end] } | |
| 383 | + | ||
| 384 | + | // QueryFontReply is a zero-copy view over a QueryFont reply; offsets count from reply byte 0. | |
| 385 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 386 | + | type QueryFontReply struct{ raw []byte } | |
| 387 | + | ||
| 388 | + | // ParseQueryFontReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 389 | + | func ParseQueryFontReply(raw []byte) (QueryFontReply, bool) { | |
| 390 | + | if len(raw) < 60 { | |
| 391 | + | return QueryFontReply{}, false | |
| 392 | + | } | |
| 393 | + | r := QueryFontReply{raw: raw} | |
| 394 | + | off := 60 | |
| 395 | + | { | |
| 396 | + | n := int(r.PropertiesLen()) | |
| 397 | + | if n < 0 || n > len(r.raw) { | |
| 398 | + | return QueryFontReply{}, false | |
| 399 | + | } | |
| 400 | + | off += n * 8 | |
| 401 | + | } | |
| 402 | + | if off > len(r.raw) { | |
| 403 | + | return QueryFontReply{}, false | |
| 404 | + | } | |
| 405 | + | { | |
| 406 | + | n := int(r.CharInfosLen()) | |
| 407 | + | if n < 0 || n > len(r.raw) { | |
| 408 | + | return QueryFontReply{}, false | |
| 409 | + | } | |
| 410 | + | off += n * 12 | |
| 411 | + | } | |
| 412 | + | if off > len(r.raw) { | |
| 413 | + | return QueryFontReply{}, false | |
| 414 | + | } | |
| 415 | + | if off > len(r.raw) { | |
| 416 | + | return QueryFontReply{}, false | |
| 417 | + | } | |
| 418 | + | return r, true | |
| 419 | + | } | |
| 420 | + | func (r QueryFontReply) Raw() []byte { return r.raw } | |
| 421 | + | func (r QueryFontReply) MinBounds() Charinfo { return GetCharinfo(r.raw[8:]) } | |
| 422 | + | func (r QueryFontReply) MaxBounds() Charinfo { return GetCharinfo(r.raw[24:]) } | |
| 423 | + | func (r QueryFontReply) MinCharOrByte2() uint16 { | |
| 424 | + | return uint16(binary.LittleEndian.Uint16(r.raw[40:])) | |
| 425 | + | } | |
| 426 | + | func (r QueryFontReply) MaxCharOrByte2() uint16 { | |
| 427 | + | return uint16(binary.LittleEndian.Uint16(r.raw[42:])) | |
| 428 | + | } | |
| 429 | + | func (r QueryFontReply) DefaultChar() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[44:])) } | |
| 430 | + | func (r QueryFontReply) PropertiesLen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[46:])) } | |
| 431 | + | func (r QueryFontReply) DrawDirection() FontDraw { return FontDraw(r.raw[48:][0]) } | |
| 432 | + | func (r QueryFontReply) MinByte1() uint8 { return uint8(r.raw[49:][0]) } | |
| 433 | + | func (r QueryFontReply) MaxByte1() uint8 { return uint8(r.raw[50:][0]) } | |
| 434 | + | func (r QueryFontReply) AllCharsExist() bool { return (r.raw[51:][0] != 0) } | |
| 435 | + | func (r QueryFontReply) FontAscent() int16 { return int16(binary.LittleEndian.Uint16(r.raw[52:])) } | |
| 436 | + | func (r QueryFontReply) FontDescent() int16 { return int16(binary.LittleEndian.Uint16(r.raw[54:])) } | |
| 437 | + | func (r QueryFontReply) CharInfosLen() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[56:])) } | |
| 438 | + | func (r QueryFontReply) Properties() FontpropList { | |
| 439 | + | off := 60 | |
| 440 | + | end := off + (int(r.PropertiesLen()))*8 | |
| 441 | + | return FontpropList{b: r.raw[off:end:end]} | |
| 442 | + | } | |
| 443 | + | func (r QueryFontReply) CharInfos() CharinfoList { | |
| 444 | + | off := 60 | |
| 445 | + | { | |
| 446 | + | n := int(r.PropertiesLen()) | |
| 447 | + | off += n * 8 | |
| 448 | + | } | |
| 449 | + | end := off + (int(r.CharInfosLen()))*12 | |
| 450 | + | return CharinfoList{b: r.raw[off:end:end]} | |
| 451 | + | } | |
| 452 | + | ||
| 453 | + | // QueryTextExtentsReply is a zero-copy view over a QueryTextExtents reply; offsets count from reply byte 0. | |
| 454 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 455 | + | type QueryTextExtentsReply struct{ raw []byte } | |
| 456 | + | ||
| 457 | + | // ParseQueryTextExtentsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 458 | + | func ParseQueryTextExtentsReply(raw []byte) (QueryTextExtentsReply, bool) { | |
| 459 | + | if len(raw) < 32 { | |
| 460 | + | return QueryTextExtentsReply{}, false | |
| 461 | + | } | |
| 462 | + | r := QueryTextExtentsReply{raw: raw} | |
| 463 | + | return r, true | |
| 464 | + | } | |
| 465 | + | func (r QueryTextExtentsReply) Raw() []byte { return r.raw } | |
| 466 | + | func (r QueryTextExtentsReply) DrawDirection() FontDraw { return FontDraw(r.raw[1:][0]) } | |
| 467 | + | func (r QueryTextExtentsReply) FontAscent() int16 { | |
| 468 | + | return int16(binary.LittleEndian.Uint16(r.raw[8:])) | |
| 469 | + | } | |
| 470 | + | func (r QueryTextExtentsReply) FontDescent() int16 { | |
| 471 | + | return int16(binary.LittleEndian.Uint16(r.raw[10:])) | |
| 472 | + | } | |
| 473 | + | func (r QueryTextExtentsReply) OverallAscent() int16 { | |
| 474 | + | return int16(binary.LittleEndian.Uint16(r.raw[12:])) | |
| 475 | + | } | |
| 476 | + | func (r QueryTextExtentsReply) OverallDescent() int16 { | |
| 477 | + | return int16(binary.LittleEndian.Uint16(r.raw[14:])) | |
| 478 | + | } | |
| 479 | + | func (r QueryTextExtentsReply) OverallWidth() int32 { | |
| 480 | + | return int32(binary.LittleEndian.Uint32(r.raw[16:])) | |
| 481 | + | } | |
| 482 | + | func (r QueryTextExtentsReply) OverallLeft() int32 { | |
| 483 | + | return int32(binary.LittleEndian.Uint32(r.raw[20:])) | |
| 484 | + | } | |
| 485 | + | func (r QueryTextExtentsReply) OverallRight() int32 { | |
| 486 | + | return int32(binary.LittleEndian.Uint32(r.raw[24:])) | |
| 487 | + | } | |
| 488 | + | ||
| 489 | + | // ListFontsReply is a zero-copy view over a ListFonts reply; offsets count from reply byte 0. | |
| 490 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 491 | + | type ListFontsReply struct{ raw []byte } | |
| 492 | + | ||
| 493 | + | // ParseListFontsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 494 | + | func ParseListFontsReply(raw []byte) (ListFontsReply, bool) { | |
| 495 | + | if len(raw) < 32 { | |
| 496 | + | return ListFontsReply{}, false | |
| 497 | + | } | |
| 498 | + | r := ListFontsReply{raw: raw} | |
| 499 | + | off := 32 | |
| 500 | + | { | |
| 501 | + | n := int(r.NamesLen()) | |
| 502 | + | if off > len(r.raw) || n < 0 || n > len(r.raw) { | |
| 503 | + | return ListFontsReply{}, false | |
| 504 | + | } | |
| 505 | + | it := NewStrIter(r.raw[off:], n) | |
| 506 | + | for it.Next() { | |
| 507 | + | off += it.Value().Size() | |
| 508 | + | } | |
| 509 | + | if it.Err() { | |
| 510 | + | return ListFontsReply{}, false | |
| 511 | + | } | |
| 512 | + | } | |
| 513 | + | if off > len(r.raw) { | |
| 514 | + | return ListFontsReply{}, false | |
| 515 | + | } | |
| 516 | + | return r, true | |
| 517 | + | } | |
| 518 | + | func (r ListFontsReply) Raw() []byte { return r.raw } | |
| 519 | + | func (r ListFontsReply) NamesLen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 520 | + | func (r ListFontsReply) Names() StrIter { off := 32; return NewStrIter(r.raw[off:], int(r.NamesLen())) } | |
| 521 | + | ||
| 522 | + | // ListFontsWithInfoReply is a zero-copy view over a ListFontsWithInfo reply; offsets count from reply byte 0. | |
| 523 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 524 | + | type ListFontsWithInfoReply struct{ raw []byte } | |
| 525 | + | ||
| 526 | + | // ParseListFontsWithInfoReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 527 | + | func ParseListFontsWithInfoReply(raw []byte) (ListFontsWithInfoReply, bool) { | |
| 528 | + | if len(raw) < 60 { | |
| 529 | + | return ListFontsWithInfoReply{}, false | |
| 530 | + | } | |
| 531 | + | r := ListFontsWithInfoReply{raw: raw} | |
| 532 | + | off := 60 | |
| 533 | + | { | |
| 534 | + | n := int(r.PropertiesLen()) | |
| 535 | + | if n < 0 || n > len(r.raw) { | |
| 536 | + | return ListFontsWithInfoReply{}, false | |
| 537 | + | } | |
| 538 | + | off += n * 8 | |
| 539 | + | } | |
| 540 | + | if off > len(r.raw) { | |
| 541 | + | return ListFontsWithInfoReply{}, false | |
| 542 | + | } | |
| 543 | + | { | |
| 544 | + | n := int(r.NameLen()) | |
| 545 | + | if n < 0 || n > len(r.raw) { | |
| 546 | + | return ListFontsWithInfoReply{}, false | |
| 547 | + | } | |
| 548 | + | off += n * 1 | |
| 549 | + | } | |
| 550 | + | if off > len(r.raw) { | |
| 551 | + | return ListFontsWithInfoReply{}, false | |
| 552 | + | } | |
| 553 | + | if off > len(r.raw) { | |
| 554 | + | return ListFontsWithInfoReply{}, false | |
| 555 | + | } | |
| 556 | + | return r, true | |
| 557 | + | } | |
| 558 | + | func (r ListFontsWithInfoReply) Raw() []byte { return r.raw } | |
| 559 | + | func (r ListFontsWithInfoReply) NameLen() uint8 { return uint8(r.raw[1:][0]) } | |
| 560 | + | func (r ListFontsWithInfoReply) MinBounds() Charinfo { return GetCharinfo(r.raw[8:]) } | |
| 561 | + | func (r ListFontsWithInfoReply) MaxBounds() Charinfo { return GetCharinfo(r.raw[24:]) } | |
| 562 | + | func (r ListFontsWithInfoReply) MinCharOrByte2() uint16 { | |
| 563 | + | return uint16(binary.LittleEndian.Uint16(r.raw[40:])) | |
| 564 | + | } | |
| 565 | + | func (r ListFontsWithInfoReply) MaxCharOrByte2() uint16 { | |
| 566 | + | return uint16(binary.LittleEndian.Uint16(r.raw[42:])) | |
| 567 | + | } | |
| 568 | + | func (r ListFontsWithInfoReply) DefaultChar() uint16 { | |
| 569 | + | return uint16(binary.LittleEndian.Uint16(r.raw[44:])) | |
| 570 | + | } | |
| 571 | + | func (r ListFontsWithInfoReply) PropertiesLen() uint16 { | |
| 572 | + | return uint16(binary.LittleEndian.Uint16(r.raw[46:])) | |
| 573 | + | } | |
| 574 | + | func (r ListFontsWithInfoReply) DrawDirection() FontDraw { return FontDraw(r.raw[48:][0]) } | |
| 575 | + | func (r ListFontsWithInfoReply) MinByte1() uint8 { return uint8(r.raw[49:][0]) } | |
| 576 | + | func (r ListFontsWithInfoReply) MaxByte1() uint8 { return uint8(r.raw[50:][0]) } | |
| 577 | + | func (r ListFontsWithInfoReply) AllCharsExist() bool { return (r.raw[51:][0] != 0) } | |
| 578 | + | func (r ListFontsWithInfoReply) FontAscent() int16 { | |
| 579 | + | return int16(binary.LittleEndian.Uint16(r.raw[52:])) | |
| 580 | + | } | |
| 581 | + | func (r ListFontsWithInfoReply) FontDescent() int16 { | |
| 582 | + | return int16(binary.LittleEndian.Uint16(r.raw[54:])) | |
| 583 | + | } | |
| 584 | + | func (r ListFontsWithInfoReply) RepliesHint() uint32 { | |
| 585 | + | return uint32(binary.LittleEndian.Uint32(r.raw[56:])) | |
| 586 | + | } | |
| 587 | + | func (r ListFontsWithInfoReply) Properties() FontpropList { | |
| 588 | + | off := 60 | |
| 589 | + | end := off + (int(r.PropertiesLen()))*8 | |
| 590 | + | return FontpropList{b: r.raw[off:end:end]} | |
| 591 | + | } | |
| 592 | + | func (r ListFontsWithInfoReply) Name() []byte { | |
| 593 | + | off := 60 | |
| 594 | + | { | |
| 595 | + | n := int(r.PropertiesLen()) | |
| 596 | + | off += n * 8 | |
| 597 | + | } | |
| 598 | + | end := off + int(r.NameLen()) | |
| 599 | + | return r.raw[off:end:end] | |
| 600 | + | } | |
| 601 | + | ||
| 602 | + | // GetFontPathReply is a zero-copy view over a GetFontPath reply; offsets count from reply byte 0. | |
| 603 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 604 | + | type GetFontPathReply struct{ raw []byte } | |
| 605 | + | ||
| 606 | + | // ParseGetFontPathReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 607 | + | func ParseGetFontPathReply(raw []byte) (GetFontPathReply, bool) { | |
| 608 | + | if len(raw) < 32 { | |
| 609 | + | return GetFontPathReply{}, false | |
| 610 | + | } | |
| 611 | + | r := GetFontPathReply{raw: raw} | |
| 612 | + | off := 32 | |
| 613 | + | { | |
| 614 | + | n := int(r.PathLen()) | |
| 615 | + | if off > len(r.raw) || n < 0 || n > len(r.raw) { | |
| 616 | + | return GetFontPathReply{}, false | |
| 617 | + | } | |
| 618 | + | it := NewStrIter(r.raw[off:], n) | |
| 619 | + | for it.Next() { | |
| 620 | + | off += it.Value().Size() | |
| 621 | + | } | |
| 622 | + | if it.Err() { | |
| 623 | + | return GetFontPathReply{}, false | |
| 624 | + | } | |
| 625 | + | } | |
| 626 | + | if off > len(r.raw) { | |
| 627 | + | return GetFontPathReply{}, false | |
| 628 | + | } | |
| 629 | + | return r, true | |
| 630 | + | } | |
| 631 | + | func (r GetFontPathReply) Raw() []byte { return r.raw } | |
| 632 | + | func (r GetFontPathReply) PathLen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 633 | + | func (r GetFontPathReply) Path() StrIter { off := 32; return NewStrIter(r.raw[off:], int(r.PathLen())) } | |
| 634 | + | ||
| 635 | + | // GetImageReply is a zero-copy view over a GetImage reply; offsets count from reply byte 0. | |
| 636 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 637 | + | type GetImageReply struct{ raw []byte } | |
| 638 | + | ||
| 639 | + | // ParseGetImageReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 640 | + | func ParseGetImageReply(raw []byte) (GetImageReply, bool) { | |
| 641 | + | if len(raw) < 32 { | |
| 642 | + | return GetImageReply{}, false | |
| 643 | + | } | |
| 644 | + | r := GetImageReply{raw: raw} | |
| 645 | + | off := 32 | |
| 646 | + | { | |
| 647 | + | n := (int(binary.LittleEndian.Uint32(r.raw[4:])) * 4) | |
| 648 | + | if n < 0 || n > len(r.raw) { | |
| 649 | + | return GetImageReply{}, false | |
| 650 | + | } | |
| 651 | + | off += n * 1 | |
| 652 | + | } | |
| 653 | + | if off > len(r.raw) { | |
| 654 | + | return GetImageReply{}, false | |
| 655 | + | } | |
| 656 | + | if off > len(r.raw) { | |
| 657 | + | return GetImageReply{}, false | |
| 658 | + | } | |
| 659 | + | return r, true | |
| 660 | + | } | |
| 661 | + | func (r GetImageReply) Raw() []byte { return r.raw } | |
| 662 | + | func (r GetImageReply) Depth() uint8 { return uint8(r.raw[1:][0]) } | |
| 663 | + | func (r GetImageReply) Visual() Visualid { return Visualid(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 664 | + | func (r GetImageReply) Data() []byte { | |
| 665 | + | off := 32 | |
| 666 | + | end := off + (int(binary.LittleEndian.Uint32(r.raw[4:])) * 4) | |
| 667 | + | return r.raw[off:end:end] | |
| 668 | + | } | |
| 669 | + | ||
| 670 | + | // ListInstalledColormapsReply is a zero-copy view over a ListInstalledColormaps reply; offsets count from reply byte 0. | |
| 671 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 672 | + | type ListInstalledColormapsReply struct{ raw []byte } | |
| 673 | + | ||
| 674 | + | // ParseListInstalledColormapsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 675 | + | func ParseListInstalledColormapsReply(raw []byte) (ListInstalledColormapsReply, bool) { | |
| 676 | + | if len(raw) < 32 { | |
| 677 | + | return ListInstalledColormapsReply{}, false | |
| 678 | + | } | |
| 679 | + | r := ListInstalledColormapsReply{raw: raw} | |
| 680 | + | off := 32 | |
| 681 | + | { | |
| 682 | + | n := int(r.CmapsLen()) | |
| 683 | + | if n < 0 || n > len(r.raw) { | |
| 684 | + | return ListInstalledColormapsReply{}, false | |
| 685 | + | } | |
| 686 | + | off += n * 4 | |
| 687 | + | } | |
| 688 | + | if off > len(r.raw) { | |
| 689 | + | return ListInstalledColormapsReply{}, false | |
| 690 | + | } | |
| 691 | + | if off > len(r.raw) { | |
| 692 | + | return ListInstalledColormapsReply{}, false | |
| 693 | + | } | |
| 694 | + | return r, true | |
| 695 | + | } | |
| 696 | + | func (r ListInstalledColormapsReply) Raw() []byte { return r.raw } | |
| 697 | + | func (r ListInstalledColormapsReply) CmapsLen() uint16 { | |
| 698 | + | return uint16(binary.LittleEndian.Uint16(r.raw[8:])) | |
| 699 | + | } | |
| 700 | + | func (r ListInstalledColormapsReply) Cmaps() ColormapList { | |
| 701 | + | off := 32 | |
| 702 | + | end := off + (int(r.CmapsLen()))*4 | |
| 703 | + | return ColormapList{b: r.raw[off:end:end]} | |
| 704 | + | } | |
| 705 | + | ||
| 706 | + | // AllocColorReply is a zero-copy view over a AllocColor reply; offsets count from reply byte 0. | |
| 707 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 708 | + | type AllocColorReply struct{ raw []byte } | |
| 709 | + | ||
| 710 | + | // ParseAllocColorReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 711 | + | func ParseAllocColorReply(raw []byte) (AllocColorReply, bool) { | |
| 712 | + | if len(raw) < 32 { | |
| 713 | + | return AllocColorReply{}, false | |
| 714 | + | } | |
| 715 | + | r := AllocColorReply{raw: raw} | |
| 716 | + | return r, true | |
| 717 | + | } | |
| 718 | + | func (r AllocColorReply) Raw() []byte { return r.raw } | |
| 719 | + | func (r AllocColorReply) Red() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 720 | + | func (r AllocColorReply) Green() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[10:])) } | |
| 721 | + | func (r AllocColorReply) Blue() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[12:])) } | |
| 722 | + | func (r AllocColorReply) Pixel() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[16:])) } | |
| 723 | + | ||
| 724 | + | // AllocNamedColorReply is a zero-copy view over a AllocNamedColor reply; offsets count from reply byte 0. | |
| 725 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 726 | + | type AllocNamedColorReply struct{ raw []byte } | |
| 727 | + | ||
| 728 | + | // ParseAllocNamedColorReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 729 | + | func ParseAllocNamedColorReply(raw []byte) (AllocNamedColorReply, bool) { | |
| 730 | + | if len(raw) < 32 { | |
| 731 | + | return AllocNamedColorReply{}, false | |
| 732 | + | } | |
| 733 | + | r := AllocNamedColorReply{raw: raw} | |
| 734 | + | return r, true | |
| 735 | + | } | |
| 736 | + | func (r AllocNamedColorReply) Raw() []byte { return r.raw } | |
| 737 | + | func (r AllocNamedColorReply) Pixel() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[8:])) } | |
| 738 | + | func (r AllocNamedColorReply) ExactRed() uint16 { | |
| 739 | + | return uint16(binary.LittleEndian.Uint16(r.raw[12:])) | |
| 740 | + | } | |
| 741 | + | func (r AllocNamedColorReply) ExactGreen() uint16 { | |
| 742 | + | return uint16(binary.LittleEndian.Uint16(r.raw[14:])) | |
| 743 | + | } | |
| 744 | + | func (r AllocNamedColorReply) ExactBlue() uint16 { | |
| 745 | + | return uint16(binary.LittleEndian.Uint16(r.raw[16:])) | |
| 746 | + | } | |
| 747 | + | func (r AllocNamedColorReply) VisualRed() uint16 { | |
| 748 | + | return uint16(binary.LittleEndian.Uint16(r.raw[18:])) | |
| 749 | + | } | |
| 750 | + | func (r AllocNamedColorReply) VisualGreen() uint16 { | |
| 751 | + | return uint16(binary.LittleEndian.Uint16(r.raw[20:])) | |
| 752 | + | } | |
| 753 | + | func (r AllocNamedColorReply) VisualBlue() uint16 { | |
| 754 | + | return uint16(binary.LittleEndian.Uint16(r.raw[22:])) | |
| 755 | + | } | |
| 756 | + | ||
| 757 | + | // AllocColorCellsReply is a zero-copy view over a AllocColorCells reply; offsets count from reply byte 0. | |
| 758 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 759 | + | type AllocColorCellsReply struct{ raw []byte } | |
| 760 | + | ||
| 761 | + | // ParseAllocColorCellsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 762 | + | func ParseAllocColorCellsReply(raw []byte) (AllocColorCellsReply, bool) { | |
| 763 | + | if len(raw) < 32 { | |
| 764 | + | return AllocColorCellsReply{}, false | |
| 765 | + | } | |
| 766 | + | r := AllocColorCellsReply{raw: raw} | |
| 767 | + | off := 32 | |
| 768 | + | { | |
| 769 | + | n := int(r.PixelsLen()) | |
| 770 | + | if n < 0 || n > len(r.raw) { | |
| 771 | + | return AllocColorCellsReply{}, false | |
| 772 | + | } | |
| 773 | + | off += n * 4 | |
| 774 | + | } | |
| 775 | + | if off > len(r.raw) { | |
| 776 | + | return AllocColorCellsReply{}, false | |
| 777 | + | } | |
| 778 | + | { | |
| 779 | + | n := int(r.MasksLen()) | |
| 780 | + | if n < 0 || n > len(r.raw) { | |
| 781 | + | return AllocColorCellsReply{}, false | |
| 782 | + | } | |
| 783 | + | off += n * 4 | |
| 784 | + | } | |
| 785 | + | if off > len(r.raw) { | |
| 786 | + | return AllocColorCellsReply{}, false | |
| 787 | + | } | |
| 788 | + | if off > len(r.raw) { | |
| 789 | + | return AllocColorCellsReply{}, false | |
| 790 | + | } | |
| 791 | + | return r, true | |
| 792 | + | } | |
| 793 | + | func (r AllocColorCellsReply) Raw() []byte { return r.raw } | |
| 794 | + | func (r AllocColorCellsReply) PixelsLen() uint16 { | |
| 795 | + | return uint16(binary.LittleEndian.Uint16(r.raw[8:])) | |
| 796 | + | } | |
| 797 | + | func (r AllocColorCellsReply) MasksLen() uint16 { | |
| 798 | + | return uint16(binary.LittleEndian.Uint16(r.raw[10:])) | |
| 799 | + | } | |
| 800 | + | func (r AllocColorCellsReply) Pixels() Uint32List { | |
| 801 | + | off := 32 | |
| 802 | + | end := off + (int(r.PixelsLen()))*4 | |
| 803 | + | return Uint32List{b: r.raw[off:end:end]} | |
| 804 | + | } | |
| 805 | + | func (r AllocColorCellsReply) Masks() Uint32List { | |
| 806 | + | off := 32 | |
| 807 | + | { | |
| 808 | + | n := int(r.PixelsLen()) | |
| 809 | + | off += n * 4 | |
| 810 | + | } | |
| 811 | + | end := off + (int(r.MasksLen()))*4 | |
| 812 | + | return Uint32List{b: r.raw[off:end:end]} | |
| 813 | + | } | |
| 814 | + | ||
| 815 | + | // AllocColorPlanesReply is a zero-copy view over a AllocColorPlanes reply; offsets count from reply byte 0. | |
| 816 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 817 | + | type AllocColorPlanesReply struct{ raw []byte } | |
| 818 | + | ||
| 819 | + | // ParseAllocColorPlanesReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 820 | + | func ParseAllocColorPlanesReply(raw []byte) (AllocColorPlanesReply, bool) { | |
| 821 | + | if len(raw) < 32 { | |
| 822 | + | return AllocColorPlanesReply{}, false | |
| 823 | + | } | |
| 824 | + | r := AllocColorPlanesReply{raw: raw} | |
| 825 | + | off := 32 | |
| 826 | + | { | |
| 827 | + | n := int(r.PixelsLen()) | |
| 828 | + | if n < 0 || n > len(r.raw) { | |
| 829 | + | return AllocColorPlanesReply{}, false | |
| 830 | + | } | |
| 831 | + | off += n * 4 | |
| 832 | + | } | |
| 833 | + | if off > len(r.raw) { | |
| 834 | + | return AllocColorPlanesReply{}, false | |
| 835 | + | } | |
| 836 | + | if off > len(r.raw) { | |
| 837 | + | return AllocColorPlanesReply{}, false | |
| 838 | + | } | |
| 839 | + | return r, true | |
| 840 | + | } | |
| 841 | + | func (r AllocColorPlanesReply) Raw() []byte { return r.raw } | |
| 842 | + | func (r AllocColorPlanesReply) PixelsLen() uint16 { | |
| 843 | + | return uint16(binary.LittleEndian.Uint16(r.raw[8:])) | |
| 844 | + | } | |
| 845 | + | func (r AllocColorPlanesReply) RedMask() uint32 { | |
| 846 | + | return uint32(binary.LittleEndian.Uint32(r.raw[12:])) | |
| 847 | + | } | |
| 848 | + | func (r AllocColorPlanesReply) GreenMask() uint32 { | |
| 849 | + | return uint32(binary.LittleEndian.Uint32(r.raw[16:])) | |
| 850 | + | } | |
| 851 | + | func (r AllocColorPlanesReply) BlueMask() uint32 { | |
| 852 | + | return uint32(binary.LittleEndian.Uint32(r.raw[20:])) | |
| 853 | + | } | |
| 854 | + | func (r AllocColorPlanesReply) Pixels() Uint32List { | |
| 855 | + | off := 32 | |
| 856 | + | end := off + (int(r.PixelsLen()))*4 | |
| 857 | + | return Uint32List{b: r.raw[off:end:end]} | |
| 858 | + | } | |
| 859 | + | ||
| 860 | + | // QueryColorsReply is a zero-copy view over a QueryColors reply; offsets count from reply byte 0. | |
| 861 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 862 | + | type QueryColorsReply struct{ raw []byte } | |
| 863 | + | ||
| 864 | + | // ParseQueryColorsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 865 | + | func ParseQueryColorsReply(raw []byte) (QueryColorsReply, bool) { | |
| 866 | + | if len(raw) < 32 { | |
| 867 | + | return QueryColorsReply{}, false | |
| 868 | + | } | |
| 869 | + | r := QueryColorsReply{raw: raw} | |
| 870 | + | off := 32 | |
| 871 | + | { | |
| 872 | + | n := int(r.ColorsLen()) | |
| 873 | + | if n < 0 || n > len(r.raw) { | |
| 874 | + | return QueryColorsReply{}, false | |
| 875 | + | } | |
| 876 | + | off += n * 8 | |
| 877 | + | } | |
| 878 | + | if off > len(r.raw) { | |
| 879 | + | return QueryColorsReply{}, false | |
| 880 | + | } | |
| 881 | + | if off > len(r.raw) { | |
| 882 | + | return QueryColorsReply{}, false | |
| 883 | + | } | |
| 884 | + | return r, true | |
| 885 | + | } | |
| 886 | + | func (r QueryColorsReply) Raw() []byte { return r.raw } | |
| 887 | + | func (r QueryColorsReply) ColorsLen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 888 | + | func (r QueryColorsReply) Colors() RgbList { | |
| 889 | + | off := 32 | |
| 890 | + | end := off + (int(r.ColorsLen()))*8 | |
| 891 | + | return RgbList{b: r.raw[off:end:end]} | |
| 892 | + | } | |
| 893 | + | ||
| 894 | + | // LookupColorReply is a zero-copy view over a LookupColor reply; offsets count from reply byte 0. | |
| 895 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 896 | + | type LookupColorReply struct{ raw []byte } | |
| 897 | + | ||
| 898 | + | // ParseLookupColorReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 899 | + | func ParseLookupColorReply(raw []byte) (LookupColorReply, bool) { | |
| 900 | + | if len(raw) < 32 { | |
| 901 | + | return LookupColorReply{}, false | |
| 902 | + | } | |
| 903 | + | r := LookupColorReply{raw: raw} | |
| 904 | + | return r, true | |
| 905 | + | } | |
| 906 | + | func (r LookupColorReply) Raw() []byte { return r.raw } | |
| 907 | + | func (r LookupColorReply) ExactRed() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 908 | + | func (r LookupColorReply) ExactGreen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[10:])) } | |
| 909 | + | func (r LookupColorReply) ExactBlue() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[12:])) } | |
| 910 | + | func (r LookupColorReply) VisualRed() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[14:])) } | |
| 911 | + | func (r LookupColorReply) VisualGreen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[16:])) } | |
| 912 | + | func (r LookupColorReply) VisualBlue() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[18:])) } | |
| 913 | + | ||
| 914 | + | // QueryBestSizeReply is a zero-copy view over a QueryBestSize reply; offsets count from reply byte 0. | |
| 915 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 916 | + | type QueryBestSizeReply struct{ raw []byte } | |
| 917 | + | ||
| 918 | + | // ParseQueryBestSizeReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 919 | + | func ParseQueryBestSizeReply(raw []byte) (QueryBestSizeReply, bool) { | |
| 920 | + | if len(raw) < 32 { | |
| 921 | + | return QueryBestSizeReply{}, false | |
| 922 | + | } | |
| 923 | + | r := QueryBestSizeReply{raw: raw} | |
| 924 | + | return r, true | |
| 925 | + | } | |
| 926 | + | func (r QueryBestSizeReply) Raw() []byte { return r.raw } | |
| 927 | + | func (r QueryBestSizeReply) Width() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 928 | + | func (r QueryBestSizeReply) Height() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[10:])) } | |
| 929 | + | ||
| 930 | + | // QueryExtensionReply is a zero-copy view over a QueryExtension reply; offsets count from reply byte 0. | |
| 931 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 932 | + | type QueryExtensionReply struct{ raw []byte } | |
| 933 | + | ||
| 934 | + | // ParseQueryExtensionReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 935 | + | func ParseQueryExtensionReply(raw []byte) (QueryExtensionReply, bool) { | |
| 936 | + | if len(raw) < 32 { | |
| 937 | + | return QueryExtensionReply{}, false | |
| 938 | + | } | |
| 939 | + | r := QueryExtensionReply{raw: raw} | |
| 940 | + | return r, true | |
| 941 | + | } | |
| 942 | + | func (r QueryExtensionReply) Raw() []byte { return r.raw } | |
| 943 | + | func (r QueryExtensionReply) Present() bool { return (r.raw[8:][0] != 0) } | |
| 944 | + | func (r QueryExtensionReply) MajorOpcode() uint8 { return uint8(r.raw[9:][0]) } | |
| 945 | + | func (r QueryExtensionReply) FirstEvent() uint8 { return uint8(r.raw[10:][0]) } | |
| 946 | + | func (r QueryExtensionReply) FirstError() uint8 { return uint8(r.raw[11:][0]) } | |
| 947 | + | ||
| 948 | + | // ListExtensionsReply is a zero-copy view over a ListExtensions reply; offsets count from reply byte 0. | |
| 949 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 950 | + | type ListExtensionsReply struct{ raw []byte } | |
| 951 | + | ||
| 952 | + | // ParseListExtensionsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 953 | + | func ParseListExtensionsReply(raw []byte) (ListExtensionsReply, bool) { | |
| 954 | + | if len(raw) < 32 { | |
| 955 | + | return ListExtensionsReply{}, false | |
| 956 | + | } | |
| 957 | + | r := ListExtensionsReply{raw: raw} | |
| 958 | + | off := 32 | |
| 959 | + | { | |
| 960 | + | n := int(r.NamesLen()) | |
| 961 | + | if off > len(r.raw) || n < 0 || n > len(r.raw) { | |
| 962 | + | return ListExtensionsReply{}, false | |
| 963 | + | } | |
| 964 | + | it := NewStrIter(r.raw[off:], n) | |
| 965 | + | for it.Next() { | |
| 966 | + | off += it.Value().Size() | |
| 967 | + | } | |
| 968 | + | if it.Err() { | |
| 969 | + | return ListExtensionsReply{}, false | |
| 970 | + | } | |
| 971 | + | } | |
| 972 | + | if off > len(r.raw) { | |
| 973 | + | return ListExtensionsReply{}, false | |
| 974 | + | } | |
| 975 | + | return r, true | |
| 976 | + | } | |
| 977 | + | func (r ListExtensionsReply) Raw() []byte { return r.raw } | |
| 978 | + | func (r ListExtensionsReply) NamesLen() uint8 { return uint8(r.raw[1:][0]) } | |
| 979 | + | func (r ListExtensionsReply) Names() StrIter { | |
| 980 | + | off := 32 | |
| 981 | + | return NewStrIter(r.raw[off:], int(r.NamesLen())) | |
| 982 | + | } | |
| 983 | + | ||
| 984 | + | // GetKeyboardMappingReply is a zero-copy view over a GetKeyboardMapping reply; offsets count from reply byte 0. | |
| 985 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 986 | + | type GetKeyboardMappingReply struct{ raw []byte } | |
| 987 | + | ||
| 988 | + | // ParseGetKeyboardMappingReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 989 | + | func ParseGetKeyboardMappingReply(raw []byte) (GetKeyboardMappingReply, bool) { | |
| 990 | + | if len(raw) < 32 { | |
| 991 | + | return GetKeyboardMappingReply{}, false | |
| 992 | + | } | |
| 993 | + | r := GetKeyboardMappingReply{raw: raw} | |
| 994 | + | off := 32 | |
| 995 | + | { | |
| 996 | + | n := int(binary.LittleEndian.Uint32(r.raw[4:])) | |
| 997 | + | if n < 0 || n > len(r.raw) { | |
| 998 | + | return GetKeyboardMappingReply{}, false | |
| 999 | + | } | |
| 1000 | + | off += n * 4 | |
| 1001 | + | } | |
| 1002 | + | if off > len(r.raw) { | |
| 1003 | + | return GetKeyboardMappingReply{}, false | |
| 1004 | + | } | |
| 1005 | + | if off > len(r.raw) { | |
| 1006 | + | return GetKeyboardMappingReply{}, false | |
| 1007 | + | } | |
| 1008 | + | return r, true | |
| 1009 | + | } | |
| 1010 | + | func (r GetKeyboardMappingReply) Raw() []byte { return r.raw } | |
| 1011 | + | func (r GetKeyboardMappingReply) KeysymsPerKeycode() byte { return byte(r.raw[1:][0]) } | |
| 1012 | + | func (r GetKeyboardMappingReply) Keysyms() KeysymList { | |
| 1013 | + | off := 32 | |
| 1014 | + | end := off + (int(binary.LittleEndian.Uint32(r.raw[4:])))*4 | |
| 1015 | + | return KeysymList{b: r.raw[off:end:end]} | |
| 1016 | + | } | |
| 1017 | + | ||
| 1018 | + | // GetKeyboardControlReply is a zero-copy view over a GetKeyboardControl reply; offsets count from reply byte 0. | |
| 1019 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 1020 | + | type GetKeyboardControlReply struct{ raw []byte } | |
| 1021 | + | ||
| 1022 | + | // ParseGetKeyboardControlReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 1023 | + | func ParseGetKeyboardControlReply(raw []byte) (GetKeyboardControlReply, bool) { | |
| 1024 | + | if len(raw) < 52 { | |
| 1025 | + | return GetKeyboardControlReply{}, false | |
| 1026 | + | } | |
| 1027 | + | r := GetKeyboardControlReply{raw: raw} | |
| 1028 | + | return r, true | |
| 1029 | + | } | |
| 1030 | + | func (r GetKeyboardControlReply) Raw() []byte { return r.raw } | |
| 1031 | + | func (r GetKeyboardControlReply) GlobalAutoRepeat() AutoRepeatMode { | |
| 1032 | + | return AutoRepeatMode(r.raw[1:][0]) | |
| 1033 | + | } | |
| 1034 | + | func (r GetKeyboardControlReply) LedMask() uint32 { | |
| 1035 | + | return uint32(binary.LittleEndian.Uint32(r.raw[8:])) | |
| 1036 | + | } | |
| 1037 | + | func (r GetKeyboardControlReply) KeyClickPercent() uint8 { return uint8(r.raw[12:][0]) } | |
| 1038 | + | func (r GetKeyboardControlReply) BellPercent() uint8 { return uint8(r.raw[13:][0]) } | |
| 1039 | + | func (r GetKeyboardControlReply) BellPitch() uint16 { | |
| 1040 | + | return uint16(binary.LittleEndian.Uint16(r.raw[14:])) | |
| 1041 | + | } | |
| 1042 | + | func (r GetKeyboardControlReply) BellDuration() uint16 { | |
| 1043 | + | return uint16(binary.LittleEndian.Uint16(r.raw[16:])) | |
| 1044 | + | } | |
| 1045 | + | func (r GetKeyboardControlReply) AutoRepeats() []byte { | |
| 1046 | + | off := 20 | |
| 1047 | + | end := off + 32 | |
| 1048 | + | return r.raw[off:end:end] | |
| 1049 | + | } | |
| 1050 | + | ||
| 1051 | + | // GetPointerControlReply is a zero-copy view over a GetPointerControl reply; offsets count from reply byte 0. | |
| 1052 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 1053 | + | type GetPointerControlReply struct{ raw []byte } | |
| 1054 | + | ||
| 1055 | + | // ParseGetPointerControlReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 1056 | + | func ParseGetPointerControlReply(raw []byte) (GetPointerControlReply, bool) { | |
| 1057 | + | if len(raw) < 32 { | |
| 1058 | + | return GetPointerControlReply{}, false | |
| 1059 | + | } | |
| 1060 | + | r := GetPointerControlReply{raw: raw} | |
| 1061 | + | return r, true | |
| 1062 | + | } | |
| 1063 | + | func (r GetPointerControlReply) Raw() []byte { return r.raw } | |
| 1064 | + | func (r GetPointerControlReply) AccelerationNumerator() uint16 { | |
| 1065 | + | return uint16(binary.LittleEndian.Uint16(r.raw[8:])) | |
| 1066 | + | } | |
| 1067 | + | func (r GetPointerControlReply) AccelerationDenominator() uint16 { | |
| 1068 | + | return uint16(binary.LittleEndian.Uint16(r.raw[10:])) | |
| 1069 | + | } | |
| 1070 | + | func (r GetPointerControlReply) Threshold() uint16 { | |
| 1071 | + | return uint16(binary.LittleEndian.Uint16(r.raw[12:])) | |
| 1072 | + | } | |
| 1073 | + | ||
| 1074 | + | // GetScreenSaverReply is a zero-copy view over a GetScreenSaver reply; offsets count from reply byte 0. | |
| 1075 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 1076 | + | type GetScreenSaverReply struct{ raw []byte } | |
| 1077 | + | ||
| 1078 | + | // ParseGetScreenSaverReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 1079 | + | func ParseGetScreenSaverReply(raw []byte) (GetScreenSaverReply, bool) { | |
| 1080 | + | if len(raw) < 32 { | |
| 1081 | + | return GetScreenSaverReply{}, false | |
| 1082 | + | } | |
| 1083 | + | r := GetScreenSaverReply{raw: raw} | |
| 1084 | + | return r, true | |
| 1085 | + | } | |
| 1086 | + | func (r GetScreenSaverReply) Raw() []byte { return r.raw } | |
| 1087 | + | func (r GetScreenSaverReply) Timeout() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 1088 | + | func (r GetScreenSaverReply) Interval() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[10:])) } | |
| 1089 | + | func (r GetScreenSaverReply) PreferBlanking() Blanking { return Blanking(r.raw[12:][0]) } | |
| 1090 | + | func (r GetScreenSaverReply) AllowExposures() Exposures { return Exposures(r.raw[13:][0]) } | |
| 1091 | + | ||
| 1092 | + | // ListHostsReply is a zero-copy view over a ListHosts reply; offsets count from reply byte 0. | |
| 1093 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 1094 | + | type ListHostsReply struct{ raw []byte } | |
| 1095 | + | ||
| 1096 | + | // ParseListHostsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 1097 | + | func ParseListHostsReply(raw []byte) (ListHostsReply, bool) { | |
| 1098 | + | if len(raw) < 32 { | |
| 1099 | + | return ListHostsReply{}, false | |
| 1100 | + | } | |
| 1101 | + | r := ListHostsReply{raw: raw} | |
| 1102 | + | off := 32 | |
| 1103 | + | { | |
| 1104 | + | n := int(r.HostsLen()) | |
| 1105 | + | if off > len(r.raw) || n < 0 || n > len(r.raw) { | |
| 1106 | + | return ListHostsReply{}, false | |
| 1107 | + | } | |
| 1108 | + | it := NewHostIter(r.raw[off:], n) | |
| 1109 | + | for it.Next() { | |
| 1110 | + | off += it.Value().Size() | |
| 1111 | + | } | |
| 1112 | + | if it.Err() { | |
| 1113 | + | return ListHostsReply{}, false | |
| 1114 | + | } | |
| 1115 | + | } | |
| 1116 | + | if off > len(r.raw) { | |
| 1117 | + | return ListHostsReply{}, false | |
| 1118 | + | } | |
| 1119 | + | return r, true | |
| 1120 | + | } | |
| 1121 | + | func (r ListHostsReply) Raw() []byte { return r.raw } | |
| 1122 | + | func (r ListHostsReply) Mode() AccessControl { return AccessControl(r.raw[1:][0]) } | |
| 1123 | + | func (r ListHostsReply) HostsLen() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) } | |
| 1124 | + | func (r ListHostsReply) Hosts() HostIter { | |
| 1125 | + | off := 32 | |
| 1126 | + | return NewHostIter(r.raw[off:], int(r.HostsLen())) | |
| 1127 | + | } | |
| 1128 | + | ||
| 1129 | + | // SetPointerMappingReply is a zero-copy view over a SetPointerMapping reply; offsets count from reply byte 0. | |
| 1130 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 1131 | + | type SetPointerMappingReply struct{ raw []byte } | |
| 1132 | + | ||
| 1133 | + | // ParseSetPointerMappingReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 1134 | + | func ParseSetPointerMappingReply(raw []byte) (SetPointerMappingReply, bool) { | |
| 1135 | + | if len(raw) < 32 { | |
| 1136 | + | return SetPointerMappingReply{}, false | |
| 1137 | + | } | |
| 1138 | + | r := SetPointerMappingReply{raw: raw} | |
| 1139 | + | return r, true | |
| 1140 | + | } | |
| 1141 | + | func (r SetPointerMappingReply) Raw() []byte { return r.raw } | |
| 1142 | + | func (r SetPointerMappingReply) Status() MappingStatus { return MappingStatus(r.raw[1:][0]) } | |
| 1143 | + | ||
| 1144 | + | // GetPointerMappingReply is a zero-copy view over a GetPointerMapping reply; offsets count from reply byte 0. | |
| 1145 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 1146 | + | type GetPointerMappingReply struct{ raw []byte } | |
| 1147 | + | ||
| 1148 | + | // ParseGetPointerMappingReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 1149 | + | func ParseGetPointerMappingReply(raw []byte) (GetPointerMappingReply, bool) { | |
| 1150 | + | if len(raw) < 32 { | |
| 1151 | + | return GetPointerMappingReply{}, false | |
| 1152 | + | } | |
| 1153 | + | r := GetPointerMappingReply{raw: raw} | |
| 1154 | + | off := 32 | |
| 1155 | + | { | |
| 1156 | + | n := int(r.MapLen()) | |
| 1157 | + | if n < 0 || n > len(r.raw) { | |
| 1158 | + | return GetPointerMappingReply{}, false | |
| 1159 | + | } | |
| 1160 | + | off += n * 1 | |
| 1161 | + | } | |
| 1162 | + | if off > len(r.raw) { | |
| 1163 | + | return GetPointerMappingReply{}, false | |
| 1164 | + | } | |
| 1165 | + | if off > len(r.raw) { | |
| 1166 | + | return GetPointerMappingReply{}, false | |
| 1167 | + | } | |
| 1168 | + | return r, true | |
| 1169 | + | } | |
| 1170 | + | func (r GetPointerMappingReply) Raw() []byte { return r.raw } | |
| 1171 | + | func (r GetPointerMappingReply) MapLen() uint8 { return uint8(r.raw[1:][0]) } | |
| 1172 | + | func (r GetPointerMappingReply) Map() []byte { | |
| 1173 | + | off := 32 | |
| 1174 | + | end := off + int(r.MapLen()) | |
| 1175 | + | return r.raw[off:end:end] | |
| 1176 | + | } | |
| 1177 | + | ||
| 1178 | + | // SetModifierMappingReply is a zero-copy view over a SetModifierMapping reply; offsets count from reply byte 0. | |
| 1179 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 1180 | + | type SetModifierMappingReply struct{ raw []byte } | |
| 1181 | + | ||
| 1182 | + | // ParseSetModifierMappingReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 1183 | + | func ParseSetModifierMappingReply(raw []byte) (SetModifierMappingReply, bool) { | |
| 1184 | + | if len(raw) < 32 { | |
| 1185 | + | return SetModifierMappingReply{}, false | |
| 1186 | + | } | |
| 1187 | + | r := SetModifierMappingReply{raw: raw} | |
| 1188 | + | return r, true | |
| 1189 | + | } | |
| 1190 | + | func (r SetModifierMappingReply) Raw() []byte { return r.raw } | |
| 1191 | + | func (r SetModifierMappingReply) Status() MappingStatus { return MappingStatus(r.raw[1:][0]) } | |
| 1192 | + | ||
| 1193 | + | // GetModifierMappingReply is a zero-copy view over a GetModifierMapping reply; offsets count from reply byte 0. | |
| 1194 | + | // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. | |
| 1195 | + | type GetModifierMappingReply struct{ raw []byte } | |
| 1196 | + | ||
| 1197 | + | // ParseGetModifierMappingReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. | |
| 1198 | + | func ParseGetModifierMappingReply(raw []byte) (GetModifierMappingReply, bool) { | |
| 1199 | + | if len(raw) < 32 { | |
| 1200 | + | return GetModifierMappingReply{}, false | |
| 1201 | + | } | |
| 1202 | + | r := GetModifierMappingReply{raw: raw} | |
| 1203 | + | off := 32 | |
| 1204 | + | { | |
| 1205 | + | n := (int(r.KeycodesPerModifier()) * 8) | |
| 1206 | + | if n < 0 || n > len(r.raw) { | |
| 1207 | + | return GetModifierMappingReply{}, false | |
| 1208 | + | } | |
| 1209 | + | off += n * 1 | |
| 1210 | + | } | |
| 1211 | + | if off > len(r.raw) { | |
| 1212 | + | return GetModifierMappingReply{}, false | |
| 1213 | + | } | |
| 1214 | + | if off > len(r.raw) { | |
| 1215 | + | return GetModifierMappingReply{}, false | |
| 1216 | + | } | |
| 1217 | + | return r, true | |
| 1218 | + | } | |
| 1219 | + | func (r GetModifierMappingReply) Raw() []byte { return r.raw } | |
| 1220 | + | func (r GetModifierMappingReply) KeycodesPerModifier() uint8 { return uint8(r.raw[1:][0]) } | |
| 1221 | + | func (r GetModifierMappingReply) Keycodes() KeycodeList { | |
| 1222 | + | off := 32 | |
| 1223 | + | end := off + (int(r.KeycodesPerModifier())*8)*1 | |
| 1224 | + | return KeycodeList{b: r.raw[off:end:end]} | |
| 1225 | + | } | |
| 1226 | + | ||
| 1227 | + | // DepthView is a zero-copy view over one wire-encoded Depth, yielded by DepthIter. | |
| 1228 | + | // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. | |
| 1229 | + | type DepthView struct{ raw []byte } | |
| 1230 | + | ||
| 1231 | + | func (v DepthView) Raw() []byte { return v.raw } | |
| 1232 | + | ||
| 1233 | + | // Size is the element's wire size, including trailing alignment. | |
| 1234 | + | func (v DepthView) Size() int { return len(v.raw) } | |
| 1235 | + | func sizeDepth(p []byte) int { | |
| 1236 | + | if len(p) < 8 { | |
| 1237 | + | return -1 | |
| 1238 | + | } | |
| 1239 | + | v := DepthView{raw: p} | |
| 1240 | + | _ = v | |
| 1241 | + | off := 8 | |
| 1242 | + | { | |
| 1243 | + | n := int(v.VisualsLen()) | |
| 1244 | + | if n < 0 || n > len(v.raw) { | |
| 1245 | + | return -1 | |
| 1246 | + | } | |
| 1247 | + | off += n * 24 | |
| 1248 | + | } | |
| 1249 | + | if off > len(v.raw) { | |
| 1250 | + | return -1 | |
| 1251 | + | } | |
| 1252 | + | if off > len(v.raw) { | |
| 1253 | + | return -1 | |
| 1254 | + | } | |
| 1255 | + | return off | |
| 1256 | + | } | |
| 1257 | + | func (v DepthView) Depth() uint8 { return uint8(v.raw[0:][0]) } | |
| 1258 | + | func (v DepthView) VisualsLen() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[2:])) } | |
| 1259 | + | func (v DepthView) Visuals() VisualtypeList { | |
| 1260 | + | off := 8 | |
| 1261 | + | end := off + (int(v.VisualsLen()))*24 | |
| 1262 | + | return VisualtypeList{b: v.raw[off:end:end]} | |
| 1263 | + | } | |
| 1264 | + | ||
| 1265 | + | // DepthIter walks n consecutive Depth elements; Err reports a malformed length. | |
| 1266 | + | // It shares the lifetime of the bytes it walks. | |
| 1267 | + | type DepthIter struct { | |
| 1268 | + | b []byte | |
| 1269 | + | n int | |
| 1270 | + | v DepthView | |
| 1271 | + | err bool | |
| 1272 | + | } | |
| 1273 | + | ||
| 1274 | + | // NewDepthIter iterates n elements encoded at the start of b. | |
| 1275 | + | func NewDepthIter(b []byte, n int) DepthIter { return DepthIter{b: b, n: n} } | |
| 1276 | + | func (it *DepthIter) Next() bool { | |
| 1277 | + | if it.n <= 0 || it.err { | |
| 1278 | + | return false | |
| 1279 | + | } | |
| 1280 | + | s := sizeDepth(it.b) | |
| 1281 | + | if s < 0 { | |
| 1282 | + | it.err = true | |
| 1283 | + | it.n = 0 | |
| 1284 | + | return false | |
| 1285 | + | } | |
| 1286 | + | it.v = DepthView{raw: it.b[:s:s]} | |
| 1287 | + | it.b = it.b[s:] | |
| 1288 | + | it.n-- | |
| 1289 | + | return true | |
| 1290 | + | } | |
| 1291 | + | func (it *DepthIter) Value() DepthView { return it.v } | |
| 1292 | + | func (it *DepthIter) Err() bool { return it.err } | |
| 1293 | + | ||
| 1294 | + | // ScreenView is a zero-copy view over one wire-encoded Screen, yielded by ScreenIter. | |
| 1295 | + | // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. | |
| 1296 | + | type ScreenView struct{ raw []byte } | |
| 1297 | + | ||
| 1298 | + | func (v ScreenView) Raw() []byte { return v.raw } | |
| 1299 | + | ||
| 1300 | + | // Size is the element's wire size, including trailing alignment. | |
| 1301 | + | func (v ScreenView) Size() int { return len(v.raw) } | |
| 1302 | + | func sizeScreen(p []byte) int { | |
| 1303 | + | if len(p) < 40 { | |
| 1304 | + | return -1 | |
| 1305 | + | } | |
| 1306 | + | v := ScreenView{raw: p} | |
| 1307 | + | _ = v | |
| 1308 | + | off := 40 | |
| 1309 | + | { | |
| 1310 | + | n := int(v.AllowedDepthsLen()) | |
| 1311 | + | if off > len(v.raw) || n < 0 || n > len(v.raw) { | |
| 1312 | + | return -1 | |
| 1313 | + | } | |
| 1314 | + | it := NewDepthIter(v.raw[off:], n) | |
| 1315 | + | for it.Next() { | |
| 1316 | + | off += it.Value().Size() | |
| 1317 | + | } | |
| 1318 | + | if it.Err() { | |
| 1319 | + | return -1 | |
| 1320 | + | } | |
| 1321 | + | } | |
| 1322 | + | if off > len(v.raw) { | |
| 1323 | + | return -1 | |
| 1324 | + | } | |
| 1325 | + | return off | |
| 1326 | + | } | |
| 1327 | + | func (v ScreenView) Root() Window { return Window(binary.LittleEndian.Uint32(v.raw[0:])) } | |
| 1328 | + | func (v ScreenView) DefaultColormap() Colormap { | |
| 1329 | + | return Colormap(binary.LittleEndian.Uint32(v.raw[4:])) | |
| 1330 | + | } | |
| 1331 | + | func (v ScreenView) WhitePixel() uint32 { return uint32(binary.LittleEndian.Uint32(v.raw[8:])) } | |
| 1332 | + | func (v ScreenView) BlackPixel() uint32 { return uint32(binary.LittleEndian.Uint32(v.raw[12:])) } | |
| 1333 | + | func (v ScreenView) CurrentInputMasks() EventMask { | |
| 1334 | + | return EventMask(binary.LittleEndian.Uint32(v.raw[16:])) | |
| 1335 | + | } | |
| 1336 | + | func (v ScreenView) WidthInPixels() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[20:])) } | |
| 1337 | + | func (v ScreenView) HeightInPixels() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[22:])) } | |
| 1338 | + | func (v ScreenView) WidthInMillimeters() uint16 { | |
| 1339 | + | return uint16(binary.LittleEndian.Uint16(v.raw[24:])) | |
| 1340 | + | } | |
| 1341 | + | func (v ScreenView) HeightInMillimeters() uint16 { | |
| 1342 | + | return uint16(binary.LittleEndian.Uint16(v.raw[26:])) | |
| 1343 | + | } | |
| 1344 | + | func (v ScreenView) MinInstalledMaps() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[28:])) } | |
| 1345 | + | func (v ScreenView) MaxInstalledMaps() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[30:])) } | |
| 1346 | + | func (v ScreenView) RootVisual() Visualid { return Visualid(binary.LittleEndian.Uint32(v.raw[32:])) } | |
| 1347 | + | func (v ScreenView) BackingStores() BackingStore { return BackingStore(v.raw[36:][0]) } | |
| 1348 | + | func (v ScreenView) SaveUnders() bool { return (v.raw[37:][0] != 0) } | |
| 1349 | + | func (v ScreenView) RootDepth() uint8 { return uint8(v.raw[38:][0]) } | |
| 1350 | + | func (v ScreenView) AllowedDepthsLen() uint8 { return uint8(v.raw[39:][0]) } | |
| 1351 | + | func (v ScreenView) AllowedDepths() DepthIter { | |
| 1352 | + | off := 40 | |
| 1353 | + | return NewDepthIter(v.raw[off:], int(v.AllowedDepthsLen())) | |
| 1354 | + | } | |
| 1355 | + | ||
| 1356 | + | // ScreenIter walks n consecutive Screen elements; Err reports a malformed length. | |
| 1357 | + | // It shares the lifetime of the bytes it walks. | |
| 1358 | + | type ScreenIter struct { | |
| 1359 | + | b []byte | |
| 1360 | + | n int | |
| 1361 | + | v ScreenView | |
| 1362 | + | err bool | |
| 1363 | + | } | |
| 1364 | + | ||
| 1365 | + | // NewScreenIter iterates n elements encoded at the start of b. | |
| 1366 | + | func NewScreenIter(b []byte, n int) ScreenIter { return ScreenIter{b: b, n: n} } | |
| 1367 | + | func (it *ScreenIter) Next() bool { | |
| 1368 | + | if it.n <= 0 || it.err { | |
| 1369 | + | return false | |
| 1370 | + | } | |
| 1371 | + | s := sizeScreen(it.b) | |
| 1372 | + | if s < 0 { | |
| 1373 | + | it.err = true | |
| 1374 | + | it.n = 0 | |
| 1375 | + | return false | |
| 1376 | + | } | |
| 1377 | + | it.v = ScreenView{raw: it.b[:s:s]} | |
| 1378 | + | it.b = it.b[s:] | |
| 1379 | + | it.n-- | |
| 1380 | + | return true | |
| 1381 | + | } | |
| 1382 | + | func (it *ScreenIter) Value() ScreenView { return it.v } | |
| 1383 | + | func (it *ScreenIter) Err() bool { return it.err } | |
| 1384 | + | ||
| 1385 | + | // SetupRequestView is a zero-copy view over one wire-encoded SetupRequest, yielded by SetupRequestIter. | |
| 1386 | + | // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. | |
| 1387 | + | type SetupRequestView struct{ raw []byte } | |
| 1388 | + | ||
| 1389 | + | func (v SetupRequestView) Raw() []byte { return v.raw } | |
| 1390 | + | ||
| 1391 | + | // Size is the element's wire size, including trailing alignment. | |
| 1392 | + | func (v SetupRequestView) Size() int { return len(v.raw) } | |
| 1393 | + | func sizeSetupRequest(p []byte) int { | |
| 1394 | + | if len(p) < 12 { | |
| 1395 | + | return -1 | |
| 1396 | + | } | |
| 1397 | + | v := SetupRequestView{raw: p} | |
| 1398 | + | _ = v | |
| 1399 | + | off := 12 | |
| 1400 | + | { | |
| 1401 | + | n := int(v.AuthorizationProtocolNameLen()) | |
| 1402 | + | if n < 0 || n > len(v.raw) { | |
| 1403 | + | return -1 | |
| 1404 | + | } | |
| 1405 | + | off += n * 1 | |
| 1406 | + | } | |
| 1407 | + | if off > len(v.raw) { | |
| 1408 | + | return -1 | |
| 1409 | + | } | |
| 1410 | + | off = (off + 3) &^ 3 | |
| 1411 | + | { | |
| 1412 | + | n := int(v.AuthorizationProtocolDataLen()) | |
| 1413 | + | if n < 0 || n > len(v.raw) { | |
| 1414 | + | return -1 | |
| 1415 | + | } | |
| 1416 | + | off += n * 1 | |
| 1417 | + | } | |
| 1418 | + | if off > len(v.raw) { | |
| 1419 | + | return -1 | |
| 1420 | + | } | |
| 1421 | + | off = (off + 3) &^ 3 | |
| 1422 | + | if off > len(v.raw) { | |
| 1423 | + | return -1 | |
| 1424 | + | } | |
| 1425 | + | return off | |
| 1426 | + | } | |
| 1427 | + | func (v SetupRequestView) ByteOrder() uint8 { return uint8(v.raw[0:][0]) } | |
| 1428 | + | func (v SetupRequestView) ProtocolMajorVersion() uint16 { | |
| 1429 | + | return uint16(binary.LittleEndian.Uint16(v.raw[2:])) | |
| 1430 | + | } | |
| 1431 | + | func (v SetupRequestView) ProtocolMinorVersion() uint16 { | |
| 1432 | + | return uint16(binary.LittleEndian.Uint16(v.raw[4:])) | |
| 1433 | + | } | |
| 1434 | + | func (v SetupRequestView) AuthorizationProtocolNameLen() uint16 { | |
| 1435 | + | return uint16(binary.LittleEndian.Uint16(v.raw[6:])) | |
| 1436 | + | } | |
| 1437 | + | func (v SetupRequestView) AuthorizationProtocolDataLen() uint16 { | |
| 1438 | + | return uint16(binary.LittleEndian.Uint16(v.raw[8:])) | |
| 1439 | + | } | |
| 1440 | + | func (v SetupRequestView) AuthorizationProtocolName() []byte { | |
| 1441 | + | off := 12 | |
| 1442 | + | end := off + int(v.AuthorizationProtocolNameLen()) | |
| 1443 | + | return v.raw[off:end:end] | |
| 1444 | + | } | |
| 1445 | + | func (v SetupRequestView) AuthorizationProtocolData() []byte { | |
| 1446 | + | off := 12 | |
| 1447 | + | { | |
| 1448 | + | n := int(v.AuthorizationProtocolNameLen()) | |
| 1449 | + | off += n * 1 | |
| 1450 | + | } | |
| 1451 | + | off = (off + 3) &^ 3 | |
| 1452 | + | end := off + int(v.AuthorizationProtocolDataLen()) | |
| 1453 | + | return v.raw[off:end:end] | |
| 1454 | + | } | |
| 1455 | + | ||
| 1456 | + | // SetupRequestIter walks n consecutive SetupRequest elements; Err reports a malformed length. | |
| 1457 | + | // It shares the lifetime of the bytes it walks. | |
| 1458 | + | type SetupRequestIter struct { | |
| 1459 | + | b []byte | |
| 1460 | + | n int | |
| 1461 | + | v SetupRequestView | |
| 1462 | + | err bool | |
| 1463 | + | } | |
| 1464 | + | ||
| 1465 | + | // NewSetupRequestIter iterates n elements encoded at the start of b. | |
| 1466 | + | func NewSetupRequestIter(b []byte, n int) SetupRequestIter { return SetupRequestIter{b: b, n: n} } | |
| 1467 | + | func (it *SetupRequestIter) Next() bool { | |
| 1468 | + | if it.n <= 0 || it.err { | |
| 1469 | + | return false | |
| 1470 | + | } | |
| 1471 | + | s := sizeSetupRequest(it.b) | |
| 1472 | + | if s < 0 { | |
| 1473 | + | it.err = true | |
| 1474 | + | it.n = 0 | |
| 1475 | + | return false | |
| 1476 | + | } | |
| 1477 | + | it.v = SetupRequestView{raw: it.b[:s:s]} | |
| 1478 | + | it.b = it.b[s:] | |
| 1479 | + | it.n-- | |
| 1480 | + | return true | |
| 1481 | + | } | |
| 1482 | + | func (it *SetupRequestIter) Value() SetupRequestView { return it.v } | |
| 1483 | + | func (it *SetupRequestIter) Err() bool { return it.err } | |
| 1484 | + | ||
| 1485 | + | // SetupFailedView is a zero-copy view over one wire-encoded SetupFailed, yielded by SetupFailedIter. | |
| 1486 | + | // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. | |
| 1487 | + | type SetupFailedView struct{ raw []byte } | |
| 1488 | + | ||
| 1489 | + | func (v SetupFailedView) Raw() []byte { return v.raw } | |
| 1490 | + | ||
| 1491 | + | // Size is the element's wire size, including trailing alignment. | |
| 1492 | + | func (v SetupFailedView) Size() int { return len(v.raw) } | |
| 1493 | + | func sizeSetupFailed(p []byte) int { | |
| 1494 | + | if len(p) < 8 { | |
| 1495 | + | return -1 | |
| 1496 | + | } | |
| 1497 | + | v := SetupFailedView{raw: p} | |
| 1498 | + | _ = v | |
| 1499 | + | off := 8 | |
| 1500 | + | { | |
| 1501 | + | n := int(v.ReasonLen()) | |
| 1502 | + | if n < 0 || n > len(v.raw) { | |
| 1503 | + | return -1 | |
| 1504 | + | } | |
| 1505 | + | off += n * 1 | |
| 1506 | + | } | |
| 1507 | + | if off > len(v.raw) { | |
| 1508 | + | return -1 | |
| 1509 | + | } | |
| 1510 | + | if off > len(v.raw) { | |
| 1511 | + | return -1 | |
| 1512 | + | } | |
| 1513 | + | return off | |
| 1514 | + | } | |
| 1515 | + | func (v SetupFailedView) Status() uint8 { return uint8(v.raw[0:][0]) } | |
| 1516 | + | func (v SetupFailedView) ReasonLen() uint8 { return uint8(v.raw[1:][0]) } | |
| 1517 | + | func (v SetupFailedView) ProtocolMajorVersion() uint16 { | |
| 1518 | + | return uint16(binary.LittleEndian.Uint16(v.raw[2:])) | |
| 1519 | + | } | |
| 1520 | + | func (v SetupFailedView) ProtocolMinorVersion() uint16 { | |
| 1521 | + | return uint16(binary.LittleEndian.Uint16(v.raw[4:])) | |
| 1522 | + | } | |
| 1523 | + | func (v SetupFailedView) Length() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[6:])) } | |
| 1524 | + | func (v SetupFailedView) Reason() []byte { | |
| 1525 | + | off := 8 | |
| 1526 | + | end := off + int(v.ReasonLen()) | |
| 1527 | + | return v.raw[off:end:end] | |
| 1528 | + | } | |
| 1529 | + | ||
| 1530 | + | // SetupFailedIter walks n consecutive SetupFailed elements; Err reports a malformed length. | |
| 1531 | + | // It shares the lifetime of the bytes it walks. | |
| 1532 | + | type SetupFailedIter struct { | |
| 1533 | + | b []byte | |
| 1534 | + | n int | |
| 1535 | + | v SetupFailedView | |
| 1536 | + | err bool | |
| 1537 | + | } | |
| 1538 | + | ||
| 1539 | + | // NewSetupFailedIter iterates n elements encoded at the start of b. | |
| 1540 | + | func NewSetupFailedIter(b []byte, n int) SetupFailedIter { return SetupFailedIter{b: b, n: n} } | |
| 1541 | + | func (it *SetupFailedIter) Next() bool { | |
| 1542 | + | if it.n <= 0 || it.err { | |
| 1543 | + | return false | |
| 1544 | + | } | |
| 1545 | + | s := sizeSetupFailed(it.b) | |
| 1546 | + | if s < 0 { | |
| 1547 | + | it.err = true | |
| 1548 | + | it.n = 0 | |
| 1549 | + | return false | |
| 1550 | + | } | |
| 1551 | + | it.v = SetupFailedView{raw: it.b[:s:s]} | |
| 1552 | + | it.b = it.b[s:] | |
| 1553 | + | it.n-- | |
| 1554 | + | return true | |
| 1555 | + | } | |
| 1556 | + | func (it *SetupFailedIter) Value() SetupFailedView { return it.v } | |
| 1557 | + | func (it *SetupFailedIter) Err() bool { return it.err } | |
| 1558 | + | ||
| 1559 | + | // SetupAuthenticateView is a zero-copy view over one wire-encoded SetupAuthenticate, yielded by SetupAuthenticateIter. | |
| 1560 | + | // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. | |
| 1561 | + | type SetupAuthenticateView struct{ raw []byte } | |
| 1562 | + | ||
| 1563 | + | func (v SetupAuthenticateView) Raw() []byte { return v.raw } | |
| 1564 | + | ||
| 1565 | + | // Size is the element's wire size, including trailing alignment. | |
| 1566 | + | func (v SetupAuthenticateView) Size() int { return len(v.raw) } | |
| 1567 | + | func sizeSetupAuthenticate(p []byte) int { | |
| 1568 | + | if len(p) < 8 { | |
| 1569 | + | return -1 | |
| 1570 | + | } | |
| 1571 | + | v := SetupAuthenticateView{raw: p} | |
| 1572 | + | _ = v | |
| 1573 | + | off := 8 | |
| 1574 | + | { | |
| 1575 | + | n := (int(v.Length()) * 4) | |
| 1576 | + | if n < 0 || n > len(v.raw) { | |
| 1577 | + | return -1 | |
| 1578 | + | } | |
| 1579 | + | off += n * 1 | |
| 1580 | + | } | |
| 1581 | + | if off > len(v.raw) { | |
| 1582 | + | return -1 | |
| 1583 | + | } | |
| 1584 | + | if off > len(v.raw) { | |
| 1585 | + | return -1 | |
| 1586 | + | } | |
| 1587 | + | return off | |
| 1588 | + | } | |
| 1589 | + | func (v SetupAuthenticateView) Status() uint8 { return uint8(v.raw[0:][0]) } | |
| 1590 | + | func (v SetupAuthenticateView) Length() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[6:])) } | |
| 1591 | + | func (v SetupAuthenticateView) Reason() []byte { | |
| 1592 | + | off := 8 | |
| 1593 | + | end := off + (int(v.Length()) * 4) | |
| 1594 | + | return v.raw[off:end:end] | |
| 1595 | + | } | |
| 1596 | + | ||
| 1597 | + | // SetupAuthenticateIter walks n consecutive SetupAuthenticate elements; Err reports a malformed length. | |
| 1598 | + | // It shares the lifetime of the bytes it walks. | |
| 1599 | + | type SetupAuthenticateIter struct { | |
| 1600 | + | b []byte | |
| 1601 | + | n int | |
| 1602 | + | v SetupAuthenticateView | |
| 1603 | + | err bool | |
| 1604 | + | } | |
| 1605 | + | ||
| 1606 | + | // NewSetupAuthenticateIter iterates n elements encoded at the start of b. | |
| 1607 | + | func NewSetupAuthenticateIter(b []byte, n int) SetupAuthenticateIter { | |
| 1608 | + | return SetupAuthenticateIter{b: b, n: n} | |
| 1609 | + | } | |
| 1610 | + | func (it *SetupAuthenticateIter) Next() bool { | |
| 1611 | + | if it.n <= 0 || it.err { | |
| 1612 | + | return false | |
| 1613 | + | } | |
| 1614 | + | s := sizeSetupAuthenticate(it.b) | |
| 1615 | + | if s < 0 { | |
| 1616 | + | it.err = true | |
| 1617 | + | it.n = 0 | |
| 1618 | + | return false | |
| 1619 | + | } | |
| 1620 | + | it.v = SetupAuthenticateView{raw: it.b[:s:s]} | |
| 1621 | + | it.b = it.b[s:] | |
| 1622 | + | it.n-- | |
| 1623 | + | return true | |
| 1624 | + | } | |
| 1625 | + | func (it *SetupAuthenticateIter) Value() SetupAuthenticateView { return it.v } | |
| 1626 | + | func (it *SetupAuthenticateIter) Err() bool { return it.err } | |
| 1627 | + | ||
| 1628 | + | // SetupView is a zero-copy view over one wire-encoded Setup, yielded by SetupIter. | |
| 1629 | + | // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. | |
| 1630 | + | type SetupView struct{ raw []byte } | |
| 1631 | + | ||
| 1632 | + | func (v SetupView) Raw() []byte { return v.raw } | |
| 1633 | + | ||
| 1634 | + | // Size is the element's wire size, including trailing alignment. | |
| 1635 | + | func (v SetupView) Size() int { return len(v.raw) } | |
| 1636 | + | func sizeSetup(p []byte) int { | |
| 1637 | + | if len(p) < 40 { | |
| 1638 | + | return -1 | |
| 1639 | + | } | |
| 1640 | + | v := SetupView{raw: p} | |
| 1641 | + | _ = v | |
| 1642 | + | off := 40 | |
| 1643 | + | { | |
| 1644 | + | n := int(v.VendorLen()) | |
| 1645 | + | if n < 0 || n > len(v.raw) { | |
| 1646 | + | return -1 | |
| 1647 | + | } | |
| 1648 | + | off += n * 1 | |
| 1649 | + | } | |
| 1650 | + | if off > len(v.raw) { | |
| 1651 | + | return -1 | |
| 1652 | + | } | |
| 1653 | + | off = (off + 3) &^ 3 | |
| 1654 | + | { | |
| 1655 | + | n := int(v.PixmapFormatsLen()) | |
| 1656 | + | if n < 0 || n > len(v.raw) { | |
| 1657 | + | return -1 | |
| 1658 | + | } | |
| 1659 | + | off += n * 8 | |
| 1660 | + | } | |
| 1661 | + | if off > len(v.raw) { | |
| 1662 | + | return -1 | |
| 1663 | + | } | |
| 1664 | + | { | |
| 1665 | + | n := int(v.RootsLen()) | |
| 1666 | + | if off > len(v.raw) || n < 0 || n > len(v.raw) { | |
| 1667 | + | return -1 | |
| 1668 | + | } | |
| 1669 | + | it := NewScreenIter(v.raw[off:], n) | |
| 1670 | + | for it.Next() { | |
| 1671 | + | off += it.Value().Size() | |
| 1672 | + | } | |
| 1673 | + | if it.Err() { | |
| 1674 | + | return -1 | |
| 1675 | + | } | |
| 1676 | + | } | |
| 1677 | + | if off > len(v.raw) { | |
| 1678 | + | return -1 | |
| 1679 | + | } | |
| 1680 | + | return off | |
| 1681 | + | } | |
| 1682 | + | func (v SetupView) Status() uint8 { return uint8(v.raw[0:][0]) } | |
| 1683 | + | func (v SetupView) ProtocolMajorVersion() uint16 { | |
| 1684 | + | return uint16(binary.LittleEndian.Uint16(v.raw[2:])) | |
| 1685 | + | } | |
| 1686 | + | func (v SetupView) ProtocolMinorVersion() uint16 { | |
| 1687 | + | return uint16(binary.LittleEndian.Uint16(v.raw[4:])) | |
| 1688 | + | } | |
| 1689 | + | func (v SetupView) Length() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[6:])) } | |
| 1690 | + | func (v SetupView) ReleaseNumber() uint32 { return uint32(binary.LittleEndian.Uint32(v.raw[8:])) } | |
| 1691 | + | func (v SetupView) ResourceIdBase() uint32 { return uint32(binary.LittleEndian.Uint32(v.raw[12:])) } | |
| 1692 | + | func (v SetupView) ResourceIdMask() uint32 { return uint32(binary.LittleEndian.Uint32(v.raw[16:])) } | |
| 1693 | + | func (v SetupView) MotionBufferSize() uint32 { return uint32(binary.LittleEndian.Uint32(v.raw[20:])) } | |
| 1694 | + | func (v SetupView) VendorLen() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[24:])) } | |
| 1695 | + | func (v SetupView) MaximumRequestLength() uint16 { | |
| 1696 | + | return uint16(binary.LittleEndian.Uint16(v.raw[26:])) | |
| 1697 | + | } | |
| 1698 | + | func (v SetupView) RootsLen() uint8 { return uint8(v.raw[28:][0]) } | |
| 1699 | + | func (v SetupView) PixmapFormatsLen() uint8 { return uint8(v.raw[29:][0]) } | |
| 1700 | + | func (v SetupView) ImageByteOrder() ImageOrder { return ImageOrder(v.raw[30:][0]) } | |
| 1701 | + | func (v SetupView) BitmapFormatBitOrder() ImageOrder { return ImageOrder(v.raw[31:][0]) } | |
| 1702 | + | func (v SetupView) BitmapFormatScanlineUnit() uint8 { return uint8(v.raw[32:][0]) } | |
| 1703 | + | func (v SetupView) BitmapFormatScanlinePad() uint8 { return uint8(v.raw[33:][0]) } | |
| 1704 | + | func (v SetupView) MinKeycode() Keycode { return Keycode(v.raw[34:][0]) } | |
| 1705 | + | func (v SetupView) MaxKeycode() Keycode { return Keycode(v.raw[35:][0]) } | |
| 1706 | + | func (v SetupView) Vendor() []byte { | |
| 1707 | + | off := 40 | |
| 1708 | + | end := off + int(v.VendorLen()) | |
| 1709 | + | return v.raw[off:end:end] | |
| 1710 | + | } | |
| 1711 | + | func (v SetupView) PixmapFormats() FormatList { | |
| 1712 | + | off := 40 | |
| 1713 | + | { | |
| 1714 | + | n := int(v.VendorLen()) | |
| 1715 | + | off += n * 1 | |
| 1716 | + | } | |
| 1717 | + | off = (off + 3) &^ 3 | |
| 1718 | + | end := off + (int(v.PixmapFormatsLen()))*8 | |
| 1719 | + | return FormatList{b: v.raw[off:end:end]} | |
| 1720 | + | } | |
| 1721 | + | func (v SetupView) Roots() ScreenIter { | |
| 1722 | + | off := 40 | |
| 1723 | + | { | |
| 1724 | + | n := int(v.VendorLen()) | |
| 1725 | + | off += n * 1 | |
| 1726 | + | } | |
| 1727 | + | off = (off + 3) &^ 3 | |
| 1728 | + | { | |
| 1729 | + | n := int(v.PixmapFormatsLen()) | |
| 1730 | + | off += n * 8 | |
| 1731 | + | } | |
| 1732 | + | return NewScreenIter(v.raw[off:], int(v.RootsLen())) | |
| 1733 | + | } | |
| 1734 | + | ||
| 1735 | + | // SetupIter walks n consecutive Setup elements; Err reports a malformed length. | |
| 1736 | + | // It shares the lifetime of the bytes it walks. | |
| 1737 | + | type SetupIter struct { | |
| 1738 | + | b []byte | |
| 1739 | + | n int | |
| 1740 | + | v SetupView | |
| 1741 | + | err bool | |
| 1742 | + | } | |
| 1743 | + | ||
| 1744 | + | // NewSetupIter iterates n elements encoded at the start of b. | |
| 1745 | + | func NewSetupIter(b []byte, n int) SetupIter { return SetupIter{b: b, n: n} } | |
| 1746 | + | func (it *SetupIter) Next() bool { | |
| 1747 | + | if it.n <= 0 || it.err { | |
| 1748 | + | return false | |
| 1749 | + | } | |
| 1750 | + | s := sizeSetup(it.b) | |
| 1751 | + | if s < 0 { | |
| 1752 | + | it.err = true | |
| 1753 | + | it.n = 0 | |
| 1754 | + | return false | |
| 1755 | + | } | |
| 1756 | + | it.v = SetupView{raw: it.b[:s:s]} | |
| 1757 | + | it.b = it.b[s:] | |
| 1758 | + | it.n-- | |
| 1759 | + | return true | |
| 1760 | + | } | |
| 1761 | + | func (it *SetupIter) Value() SetupView { return it.v } | |
| 1762 | + | func (it *SetupIter) Err() bool { return it.err } | |
| 1763 | + | ||
| 1764 | + | // StrView is a zero-copy view over one wire-encoded Str, yielded by StrIter. | |
| 1765 | + | // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. | |
| 1766 | + | type StrView struct{ raw []byte } | |
| 1767 | + | ||
| 1768 | + | func (v StrView) Raw() []byte { return v.raw } | |
| 1769 | + | ||
| 1770 | + | // Size is the element's wire size, including trailing alignment. | |
| 1771 | + | func (v StrView) Size() int { return len(v.raw) } | |
| 1772 | + | func sizeStr(p []byte) int { | |
| 1773 | + | if len(p) < 1 { | |
| 1774 | + | return -1 | |
| 1775 | + | } | |
| 1776 | + | v := StrView{raw: p} | |
| 1777 | + | _ = v | |
| 1778 | + | off := 1 | |
| 1779 | + | { | |
| 1780 | + | n := int(v.NameLen()) | |
| 1781 | + | if n < 0 || n > len(v.raw) { | |
| 1782 | + | return -1 | |
| 1783 | + | } | |
| 1784 | + | off += n * 1 | |
| 1785 | + | } | |
| 1786 | + | if off > len(v.raw) { | |
| 1787 | + | return -1 | |
| 1788 | + | } | |
| 1789 | + | if off > len(v.raw) { | |
| 1790 | + | return -1 | |
| 1791 | + | } | |
| 1792 | + | return off | |
| 1793 | + | } | |
| 1794 | + | func (v StrView) NameLen() uint8 { return uint8(v.raw[0:][0]) } | |
| 1795 | + | func (v StrView) Name() []byte { off := 1; end := off + int(v.NameLen()); return v.raw[off:end:end] } | |
| 1796 | + | ||
| 1797 | + | // StrIter walks n consecutive Str elements; Err reports a malformed length. | |
| 1798 | + | // It shares the lifetime of the bytes it walks. | |
| 1799 | + | type StrIter struct { | |
| 1800 | + | b []byte | |
| 1801 | + | n int | |
| 1802 | + | v StrView | |
| 1803 | + | err bool | |
| 1804 | + | } | |
| 1805 | + | ||
| 1806 | + | // NewStrIter iterates n elements encoded at the start of b. | |
| 1807 | + | func NewStrIter(b []byte, n int) StrIter { return StrIter{b: b, n: n} } | |
| 1808 | + | func (it *StrIter) Next() bool { | |
| 1809 | + | if it.n <= 0 || it.err { | |
| 1810 | + | return false | |
| 1811 | + | } | |
| 1812 | + | s := sizeStr(it.b) | |
| 1813 | + | if s < 0 { | |
| 1814 | + | it.err = true | |
| 1815 | + | it.n = 0 | |
| 1816 | + | return false | |
| 1817 | + | } | |
| 1818 | + | it.v = StrView{raw: it.b[:s:s]} | |
| 1819 | + | it.b = it.b[s:] | |
| 1820 | + | it.n-- | |
| 1821 | + | return true | |
| 1822 | + | } | |
| 1823 | + | func (it *StrIter) Value() StrView { return it.v } | |
| 1824 | + | func (it *StrIter) Err() bool { return it.err } | |
| 1825 | + | ||
| 1826 | + | // HostView is a zero-copy view over one wire-encoded Host, yielded by HostIter. | |
| 1827 | + | // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. | |
| 1828 | + | type HostView struct{ raw []byte } | |
| 1829 | + | ||
| 1830 | + | func (v HostView) Raw() []byte { return v.raw } | |
| 1831 | + | ||
| 1832 | + | // Size is the element's wire size, including trailing alignment. | |
| 1833 | + | func (v HostView) Size() int { return len(v.raw) } | |
| 1834 | + | func sizeHost(p []byte) int { | |
| 1835 | + | if len(p) < 4 { | |
| 1836 | + | return -1 | |
| 1837 | + | } | |
| 1838 | + | v := HostView{raw: p} | |
| 1839 | + | _ = v | |
| 1840 | + | off := 4 | |
| 1841 | + | { | |
| 1842 | + | n := int(v.AddressLen()) | |
| 1843 | + | if n < 0 || n > len(v.raw) { | |
| 1844 | + | return -1 | |
| 1845 | + | } | |
| 1846 | + | off += n * 1 | |
| 1847 | + | } | |
| 1848 | + | if off > len(v.raw) { | |
| 1849 | + | return -1 | |
| 1850 | + | } | |
| 1851 | + | off = (off + 3) &^ 3 | |
| 1852 | + | if off > len(v.raw) { | |
| 1853 | + | return -1 | |
| 1854 | + | } | |
| 1855 | + | return off | |
| 1856 | + | } | |
| 1857 | + | func (v HostView) Family() Family { return Family(v.raw[0:][0]) } | |
| 1858 | + | func (v HostView) AddressLen() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[2:])) } | |
| 1859 | + | func (v HostView) Address() []byte { | |
| 1860 | + | off := 4 | |
| 1861 | + | end := off + int(v.AddressLen()) | |
| 1862 | + | return v.raw[off:end:end] | |
| 1863 | + | } | |
| 1864 | + | ||
| 1865 | + | // HostIter walks n consecutive Host elements; Err reports a malformed length. | |
| 1866 | + | // It shares the lifetime of the bytes it walks. | |
| 1867 | + | type HostIter struct { | |
| 1868 | + | b []byte | |
| 1869 | + | n int | |
| 1870 | + | v HostView | |
| 1871 | + | err bool | |
| 1872 | + | } | |
| 1873 | + | ||
| 1874 | + | // NewHostIter iterates n elements encoded at the start of b. | |
| 1875 | + | func NewHostIter(b []byte, n int) HostIter { return HostIter{b: b, n: n} } | |
| 1876 | + | func (it *HostIter) Next() bool { | |
| 1877 | + | if it.n <= 0 || it.err { | |
| 1878 | + | return false | |
| 1879 | + | } | |
| 1880 | + | s := sizeHost(it.b) | |
| 1881 | + | if s < 0 { | |
| 1882 | + | it.err = true | |
| 1883 | + | it.n = 0 | |
| 1884 | + | return false | |
| 1885 | + | } | |
| 1886 | + | it.v = HostView{raw: it.b[:s:s]} | |
| 1887 | + | it.b = it.b[s:] | |
| 1888 | + | it.n-- | |
| 1889 | + | return true | |
| 1890 | + | } | |
| 1891 | + | func (it *HostIter) Value() HostView { return it.v } | |
| 1892 | + | func (it *HostIter) Err() bool { return it.err } | |
| 1893 | + | ||
| 1894 | + | // AtomList is a borrowed view over a wire list of Atom. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1895 | + | type AtomList struct{ b []byte } | |
| 1896 | + | ||
| 1897 | + | func (l AtomList) Len() int { return len(l.b) / 4 } | |
| 1898 | + | func (l AtomList) At(i int) Atom { return Atom(binary.LittleEndian.Uint32(l.b[i*4:])) } | |
| 1899 | + | ||
| 1900 | + | // CharinfoList is a borrowed view over a wire list of Charinfo. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1901 | + | type CharinfoList struct{ b []byte } | |
| 1902 | + | ||
| 1903 | + | func (l CharinfoList) Len() int { return len(l.b) / 12 } | |
| 1904 | + | func (l CharinfoList) At(i int) Charinfo { return GetCharinfo(l.b[i*12:]) } | |
| 1905 | + | ||
| 1906 | + | // ColormapList is a borrowed view over a wire list of Colormap. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1907 | + | type ColormapList struct{ b []byte } | |
| 1908 | + | ||
| 1909 | + | func (l ColormapList) Len() int { return len(l.b) / 4 } | |
| 1910 | + | func (l ColormapList) At(i int) Colormap { return Colormap(binary.LittleEndian.Uint32(l.b[i*4:])) } | |
| 1911 | + | ||
| 1912 | + | // FontpropList is a borrowed view over a wire list of Fontprop. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1913 | + | type FontpropList struct{ b []byte } | |
| 1914 | + | ||
| 1915 | + | func (l FontpropList) Len() int { return len(l.b) / 8 } | |
| 1916 | + | func (l FontpropList) At(i int) Fontprop { return GetFontprop(l.b[i*8:]) } | |
| 1917 | + | ||
| 1918 | + | // FormatList is a borrowed view over a wire list of Format. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1919 | + | type FormatList struct{ b []byte } | |
| 1920 | + | ||
| 1921 | + | func (l FormatList) Len() int { return len(l.b) / 8 } | |
| 1922 | + | func (l FormatList) At(i int) Format { return GetFormat(l.b[i*8:]) } | |
| 1923 | + | ||
| 1924 | + | // KeycodeList is a borrowed view over a wire list of Keycode. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1925 | + | type KeycodeList struct{ b []byte } | |
| 1926 | + | ||
| 1927 | + | func (l KeycodeList) Len() int { return len(l.b) / 1 } | |
| 1928 | + | func (l KeycodeList) At(i int) Keycode { return Keycode(l.b[i*1:][0]) } | |
| 1929 | + | ||
| 1930 | + | // KeysymList is a borrowed view over a wire list of Keysym. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1931 | + | type KeysymList struct{ b []byte } | |
| 1932 | + | ||
| 1933 | + | func (l KeysymList) Len() int { return len(l.b) / 4 } | |
| 1934 | + | func (l KeysymList) At(i int) Keysym { return Keysym(binary.LittleEndian.Uint32(l.b[i*4:])) } | |
| 1935 | + | ||
| 1936 | + | // RgbList is a borrowed view over a wire list of Rgb. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1937 | + | type RgbList struct{ b []byte } | |
| 1938 | + | ||
| 1939 | + | func (l RgbList) Len() int { return len(l.b) / 8 } | |
| 1940 | + | func (l RgbList) At(i int) Rgb { return GetRgb(l.b[i*8:]) } | |
| 1941 | + | ||
| 1942 | + | // TimecoordList is a borrowed view over a wire list of Timecoord. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1943 | + | type TimecoordList struct{ b []byte } | |
| 1944 | + | ||
| 1945 | + | func (l TimecoordList) Len() int { return len(l.b) / 8 } | |
| 1946 | + | func (l TimecoordList) At(i int) Timecoord { return GetTimecoord(l.b[i*8:]) } | |
| 1947 | + | ||
| 1948 | + | // Uint32List is a borrowed view over a wire list of uint32. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1949 | + | type Uint32List struct{ b []byte } | |
| 1950 | + | ||
| 1951 | + | func (l Uint32List) Len() int { return len(l.b) / 4 } | |
| 1952 | + | func (l Uint32List) At(i int) uint32 { return uint32(binary.LittleEndian.Uint32(l.b[i*4:])) } | |
| 1953 | + | ||
| 1954 | + | // VisualtypeList is a borrowed view over a wire list of Visualtype. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1955 | + | type VisualtypeList struct{ b []byte } | |
| 1956 | + | ||
| 1957 | + | func (l VisualtypeList) Len() int { return len(l.b) / 24 } | |
| 1958 | + | func (l VisualtypeList) At(i int) Visualtype { return GetVisualtype(l.b[i*24:]) } | |
| 1959 | + | ||
| 1960 | + | // WindowList is a borrowed view over a wire list of Window. It shares the lifetime of the bytes it was taken from; copy what you keep. | |
| 1961 | + | type WindowList struct{ b []byte } | |
| 1962 | + | ||
| 1963 | + | func (l WindowList) Len() int { return len(l.b) / 4 } | |
| 1964 | + | func (l WindowList) At(i int) Window { return Window(binary.LittleEndian.Uint32(l.b[i*4:])) } | |
A xproto/requests_generated.go +2780 -0 large diff (2780 lines changed): collapsed
A xproto/requests_test.go +83 -0
| @@ -0,0 +1,83 @@ | |||
| 1 | + | package xproto | |
| 2 | + | ||
| 3 | + | import ( | |
| 4 | + | "bnema.dev/xturbo" | |
| 5 | + | "testing" | |
| 6 | + | ) | |
| 7 | + | ||
| 8 | + | func BenchmarkConfigureWindow(b *testing.B) { | |
| 9 | + | buf := xturbo.NewBuf(0) | |
| 10 | + | var v ConfigureWindowValues | |
| 11 | + | v.SetX(-1).SetY(-2).SetWidth(800).SetHeight(600).SetBorderWidth(1).SetSibling(2).SetStackMode(StackModeAbove) | |
| 12 | + | batch := 0 | |
| 13 | + | b.ReportAllocs() | |
| 14 | + | b.ResetTimer() | |
| 15 | + | for i := 0; i < b.N; i++ { | |
| 16 | + | if batch == 60000 { | |
| 17 | + | b.StopTimer() | |
| 18 | + | buf = xturbo.NewBuf(0) | |
| 19 | + | batch = 0 | |
| 20 | + | b.StartTimer() | |
| 21 | + | } | |
| 22 | + | buf.Reset() | |
| 23 | + | ConfigureWindow(buf, 1, &v) | |
| 24 | + | batch++ | |
| 25 | + | } | |
| 26 | + | if buf.Err() != nil { | |
| 27 | + | b.Fatal(buf.Err()) | |
| 28 | + | } | |
| 29 | + | } | |
| 30 | + | ||
| 31 | + | func BenchmarkMapWindow(b *testing.B) { | |
| 32 | + | buf := xturbo.NewBuf(0) | |
| 33 | + | batch := 0 | |
| 34 | + | b.ReportAllocs() | |
| 35 | + | b.ResetTimer() | |
| 36 | + | for i := 0; i < b.N; i++ { | |
| 37 | + | if batch == 60000 { | |
| 38 | + | b.StopTimer() | |
| 39 | + | buf = xturbo.NewBuf(0) | |
| 40 | + | batch = 0 | |
| 41 | + | b.StartTimer() | |
| 42 | + | } | |
| 43 | + | buf.Reset() | |
| 44 | + | MapWindow(buf, 1) | |
| 45 | + | batch++ | |
| 46 | + | } | |
| 47 | + | } | |
| 48 | + | ||
| 49 | + | func BenchmarkInternAtom(b *testing.B) { | |
| 50 | + | buf := xturbo.NewBuf(0) | |
| 51 | + | batch := 0 | |
| 52 | + | b.ReportAllocs() | |
| 53 | + | b.ResetTimer() | |
| 54 | + | for i := 0; i < b.N; i++ { | |
| 55 | + | if batch == 60000 { | |
| 56 | + | b.StopTimer() | |
| 57 | + | buf = xturbo.NewBuf(0) | |
| 58 | + | batch = 0 | |
| 59 | + | b.StartTimer() | |
| 60 | + | } | |
| 61 | + | buf.Reset() | |
| 62 | + | InternAtom(buf, false, "WM_CLASS") | |
| 63 | + | batch++ | |
| 64 | + | } | |
| 65 | + | } | |
| 66 | + | func BenchmarkChangeProperty4KiB(b *testing.B) { | |
| 67 | + | buf := xturbo.NewBuf(0) | |
| 68 | + | data := make([]byte, 4096) | |
| 69 | + | batch := 0 | |
| 70 | + | b.ReportAllocs() | |
| 71 | + | b.ResetTimer() | |
| 72 | + | for i := 0; i < b.N; i++ { | |
| 73 | + | if batch == 60000 { | |
| 74 | + | b.StopTimer() | |
| 75 | + | buf = xturbo.NewBuf(0) | |
| 76 | + | batch = 0 | |
| 77 | + | b.StartTimer() | |
| 78 | + | } | |
| 79 | + | buf.Reset() | |
| 80 | + | ChangeProperty(buf, 0, 1, 1, 1, 8, 4096, data) | |
| 81 | + | batch++ | |
| 82 | + | } | |
| 83 | + | } | |
A xproto/sizes_test.go +293 -0
| @@ -0,0 +1,293 @@ | |||
| 1 | + | // Code generated by xtgen; DO NOT EDIT. | |
| 2 | + | package xproto | |
| 3 | + | ||
| 4 | + | import "testing" | |
| 5 | + | ||
| 6 | + | func TestWireSizes(t *testing.T) { | |
| 7 | + | if Char2bSize != 2 { | |
| 8 | + | t.Errorf("Char2b fixed prefix = %d", Char2bSize) | |
| 9 | + | } | |
| 10 | + | if PointSize != 4 { | |
| 11 | + | t.Errorf("Point fixed prefix = %d", PointSize) | |
| 12 | + | } | |
| 13 | + | if RectangleSize != 8 { | |
| 14 | + | t.Errorf("Rectangle fixed prefix = %d", RectangleSize) | |
| 15 | + | } | |
| 16 | + | if ArcSize != 12 { | |
| 17 | + | t.Errorf("Arc fixed prefix = %d", ArcSize) | |
| 18 | + | } | |
| 19 | + | if FormatSize != 8 { | |
| 20 | + | t.Errorf("Format fixed prefix = %d", FormatSize) | |
| 21 | + | } | |
| 22 | + | if VisualtypeSize != 24 { | |
| 23 | + | t.Errorf("Visualtype fixed prefix = %d", VisualtypeSize) | |
| 24 | + | } | |
| 25 | + | if DepthSize != 8 { | |
| 26 | + | t.Errorf("Depth fixed prefix = %d", DepthSize) | |
| 27 | + | } | |
| 28 | + | if ScreenSize != 40 { | |
| 29 | + | t.Errorf("Screen fixed prefix = %d", ScreenSize) | |
| 30 | + | } | |
| 31 | + | if SetupRequestSize != 12 { | |
| 32 | + | t.Errorf("SetupRequest fixed prefix = %d", SetupRequestSize) | |
| 33 | + | } | |
| 34 | + | if SetupFailedSize != 8 { | |
| 35 | + | t.Errorf("SetupFailed fixed prefix = %d", SetupFailedSize) | |
| 36 | + | } | |
| 37 | + | if SetupAuthenticateSize != 8 { | |
| 38 | + | t.Errorf("SetupAuthenticate fixed prefix = %d", SetupAuthenticateSize) | |
| 39 | + | } | |
| 40 | + | if SetupSize != 40 { | |
| 41 | + | t.Errorf("Setup fixed prefix = %d", SetupSize) | |
| 42 | + | } | |
| 43 | + | if ClientMessageDataSize != 20 { | |
| 44 | + | t.Errorf("ClientMessageData fixed prefix = %d", ClientMessageDataSize) | |
| 45 | + | } | |
| 46 | + | if TimecoordSize != 8 { | |
| 47 | + | t.Errorf("Timecoord fixed prefix = %d", TimecoordSize) | |
| 48 | + | } | |
| 49 | + | if FontpropSize != 8 { | |
| 50 | + | t.Errorf("Fontprop fixed prefix = %d", FontpropSize) | |
| 51 | + | } | |
| 52 | + | if CharinfoSize != 12 { | |
| 53 | + | t.Errorf("Charinfo fixed prefix = %d", CharinfoSize) | |
| 54 | + | } | |
| 55 | + | if StrSize != 1 { | |
| 56 | + | t.Errorf("Str fixed prefix = %d", StrSize) | |
| 57 | + | } | |
| 58 | + | if SegmentSize != 8 { | |
| 59 | + | t.Errorf("Segment fixed prefix = %d", SegmentSize) | |
| 60 | + | } | |
| 61 | + | if ColoritemSize != 12 { | |
| 62 | + | t.Errorf("Coloritem fixed prefix = %d", ColoritemSize) | |
| 63 | + | } | |
| 64 | + | if RgbSize != 8 { | |
| 65 | + | t.Errorf("Rgb fixed prefix = %d", RgbSize) | |
| 66 | + | } | |
| 67 | + | if HostSize != 4 { | |
| 68 | + | t.Errorf("Host fixed prefix = %d", HostSize) | |
| 69 | + | } | |
| 70 | + | if got := 32; got != 32 { | |
| 71 | + | t.Errorf("event KeyPress fixed size = %d", got) | |
| 72 | + | } | |
| 73 | + | if got := 32; got != 32 { | |
| 74 | + | t.Errorf("event KeyRelease fixed size = %d", got) | |
| 75 | + | } | |
| 76 | + | if got := 32; got != 32 { | |
| 77 | + | t.Errorf("event ButtonPress fixed size = %d", got) | |
| 78 | + | } | |
| 79 | + | if got := 32; got != 32 { | |
| 80 | + | t.Errorf("event ButtonRelease fixed size = %d", got) | |
| 81 | + | } | |
| 82 | + | if got := 32; got != 32 { | |
| 83 | + | t.Errorf("event MotionNotify fixed size = %d", got) | |
| 84 | + | } | |
| 85 | + | if got := 32; got != 32 { | |
| 86 | + | t.Errorf("event EnterNotify fixed size = %d", got) | |
| 87 | + | } | |
| 88 | + | if got := 32; got != 32 { | |
| 89 | + | t.Errorf("event LeaveNotify fixed size = %d", got) | |
| 90 | + | } | |
| 91 | + | if got := 32; got != 32 { | |
| 92 | + | t.Errorf("event FocusIn fixed size = %d", got) | |
| 93 | + | } | |
| 94 | + | if got := 32; got != 32 { | |
| 95 | + | t.Errorf("event FocusOut fixed size = %d", got) | |
| 96 | + | } | |
| 97 | + | if got := 32; got != 32 { | |
| 98 | + | t.Errorf("event KeymapNotify fixed size = %d", got) | |
| 99 | + | } | |
| 100 | + | if got := 32; got != 32 { | |
| 101 | + | t.Errorf("event Expose fixed size = %d", got) | |
| 102 | + | } | |
| 103 | + | if got := 32; got != 32 { | |
| 104 | + | t.Errorf("event GraphicsExposure fixed size = %d", got) | |
| 105 | + | } | |
| 106 | + | if got := 32; got != 32 { | |
| 107 | + | t.Errorf("event NoExposure fixed size = %d", got) | |
| 108 | + | } | |
| 109 | + | if got := 32; got != 32 { | |
| 110 | + | t.Errorf("event VisibilityNotify fixed size = %d", got) | |
| 111 | + | } | |
| 112 | + | if got := 32; got != 32 { | |
| 113 | + | t.Errorf("event CreateNotify fixed size = %d", got) | |
| 114 | + | } | |
| 115 | + | if got := 32; got != 32 { | |
| 116 | + | t.Errorf("event DestroyNotify fixed size = %d", got) | |
| 117 | + | } | |
| 118 | + | if got := 32; got != 32 { | |
| 119 | + | t.Errorf("event UnmapNotify fixed size = %d", got) | |
| 120 | + | } | |
| 121 | + | if got := 32; got != 32 { | |
| 122 | + | t.Errorf("event MapNotify fixed size = %d", got) | |
| 123 | + | } | |
| 124 | + | if got := 32; got != 32 { | |
| 125 | + | t.Errorf("event MapRequest fixed size = %d", got) | |
| 126 | + | } | |
| 127 | + | if got := 32; got != 32 { | |
| 128 | + | t.Errorf("event ReparentNotify fixed size = %d", got) | |
| 129 | + | } | |
| 130 | + | if got := 32; got != 32 { | |
| 131 | + | t.Errorf("event ConfigureNotify fixed size = %d", got) | |
| 132 | + | } | |
| 133 | + | if got := 32; got != 32 { | |
| 134 | + | t.Errorf("event ConfigureRequest fixed size = %d", got) | |
| 135 | + | } | |
| 136 | + | if got := 32; got != 32 { | |
| 137 | + | t.Errorf("event GravityNotify fixed size = %d", got) | |
| 138 | + | } | |
| 139 | + | if got := 32; got != 32 { | |
| 140 | + | t.Errorf("event ResizeRequest fixed size = %d", got) | |
| 141 | + | } | |
| 142 | + | if got := 32; got != 32 { | |
| 143 | + | t.Errorf("event CirculateNotify fixed size = %d", got) | |
| 144 | + | } | |
| 145 | + | if got := 32; got != 32 { | |
| 146 | + | t.Errorf("event CirculateRequest fixed size = %d", got) | |
| 147 | + | } | |
| 148 | + | if got := 32; got != 32 { | |
| 149 | + | t.Errorf("event PropertyNotify fixed size = %d", got) | |
| 150 | + | } | |
| 151 | + | if got := 32; got != 32 { | |
| 152 | + | t.Errorf("event SelectionClear fixed size = %d", got) | |
| 153 | + | } | |
| 154 | + | if got := 32; got != 32 { | |
| 155 | + | t.Errorf("event SelectionRequest fixed size = %d", got) | |
| 156 | + | } | |
| 157 | + | if got := 32; got != 32 { | |
| 158 | + | t.Errorf("event SelectionNotify fixed size = %d", got) | |
| 159 | + | } | |
| 160 | + | if got := 32; got != 32 { | |
| 161 | + | t.Errorf("event ColormapNotify fixed size = %d", got) | |
| 162 | + | } | |
| 163 | + | if got := 32; got != 32 { | |
| 164 | + | t.Errorf("event ClientMessage fixed size = %d", got) | |
| 165 | + | } | |
| 166 | + | if got := 32; got != 32 { | |
| 167 | + | t.Errorf("event MappingNotify fixed size = %d", got) | |
| 168 | + | } | |
| 169 | + | if got := 32; got != 32 { | |
| 170 | + | t.Errorf("event GeGeneric fixed size = %d", got) | |
| 171 | + | } | |
| 172 | + | if got := 44; got != 44 { | |
| 173 | + | t.Errorf("reply GetWindowAttributes fixed size = %d", got) | |
| 174 | + | } | |
| 175 | + | if got := 32; got != 32 { | |
| 176 | + | t.Errorf("reply GetGeometry fixed size = %d", got) | |
| 177 | + | } | |
| 178 | + | if got := 32; got != 32 { | |
| 179 | + | t.Errorf("reply QueryTree fixed size = %d", got) | |
| 180 | + | } | |
| 181 | + | if got := 32; got != 32 { | |
| 182 | + | t.Errorf("reply InternAtom fixed size = %d", got) | |
| 183 | + | } | |
| 184 | + | if got := 32; got != 32 { | |
| 185 | + | t.Errorf("reply GetAtomName fixed size = %d", got) | |
| 186 | + | } | |
| 187 | + | if got := 32; got != 32 { | |
| 188 | + | t.Errorf("reply GetProperty fixed size = %d", got) | |
| 189 | + | } | |
| 190 | + | if got := 32; got != 32 { | |
| 191 | + | t.Errorf("reply ListProperties fixed size = %d", got) | |
| 192 | + | } | |
| 193 | + | if got := 32; got != 32 { | |
| 194 | + | t.Errorf("reply GetSelectionOwner fixed size = %d", got) | |
| 195 | + | } | |
| 196 | + | if got := 32; got != 32 { | |
| 197 | + | t.Errorf("reply GrabPointer fixed size = %d", got) | |
| 198 | + | } | |
| 199 | + | if got := 32; got != 32 { | |
| 200 | + | t.Errorf("reply GrabKeyboard fixed size = %d", got) | |
| 201 | + | } | |
| 202 | + | if got := 32; got != 32 { | |
| 203 | + | t.Errorf("reply QueryPointer fixed size = %d", got) | |
| 204 | + | } | |
| 205 | + | if got := 32; got != 32 { | |
| 206 | + | t.Errorf("reply GetMotionEvents fixed size = %d", got) | |
| 207 | + | } | |
| 208 | + | if got := 32; got != 32 { | |
| 209 | + | t.Errorf("reply TranslateCoordinates fixed size = %d", got) | |
| 210 | + | } | |
| 211 | + | if got := 32; got != 32 { | |
| 212 | + | t.Errorf("reply GetInputFocus fixed size = %d", got) | |
| 213 | + | } | |
| 214 | + | if got := 40; got != 40 { | |
| 215 | + | t.Errorf("reply QueryKeymap fixed size = %d", got) | |
| 216 | + | } | |
| 217 | + | if got := 60; got != 60 { | |
| 218 | + | t.Errorf("reply QueryFont fixed size = %d", got) | |
| 219 | + | } | |
| 220 | + | if got := 32; got != 32 { | |
| 221 | + | t.Errorf("reply QueryTextExtents fixed size = %d", got) | |
| 222 | + | } | |
| 223 | + | if got := 32; got != 32 { | |
| 224 | + | t.Errorf("reply ListFonts fixed size = %d", got) | |
| 225 | + | } | |
| 226 | + | if got := 60; got != 60 { | |
| 227 | + | t.Errorf("reply ListFontsWithInfo fixed size = %d", got) | |
| 228 | + | } | |
| 229 | + | if got := 32; got != 32 { | |
| 230 | + | t.Errorf("reply GetFontPath fixed size = %d", got) | |
| 231 | + | } | |
| 232 | + | if got := 32; got != 32 { | |
| 233 | + | t.Errorf("reply GetImage fixed size = %d", got) | |
| 234 | + | } | |
| 235 | + | if got := 32; got != 32 { | |
| 236 | + | t.Errorf("reply ListInstalledColormaps fixed size = %d", got) | |
| 237 | + | } | |
| 238 | + | if got := 32; got != 32 { | |
| 239 | + | t.Errorf("reply AllocColor fixed size = %d", got) | |
| 240 | + | } | |
| 241 | + | if got := 32; got != 32 { | |
| 242 | + | t.Errorf("reply AllocNamedColor fixed size = %d", got) | |
| 243 | + | } | |
| 244 | + | if got := 32; got != 32 { | |
| 245 | + | t.Errorf("reply AllocColorCells fixed size = %d", got) | |
| 246 | + | } | |
| 247 | + | if got := 32; got != 32 { | |
| 248 | + | t.Errorf("reply AllocColorPlanes fixed size = %d", got) | |
| 249 | + | } | |
| 250 | + | if got := 32; got != 32 { | |
| 251 | + | t.Errorf("reply QueryColors fixed size = %d", got) | |
| 252 | + | } | |
| 253 | + | if got := 32; got != 32 { | |
| 254 | + | t.Errorf("reply LookupColor fixed size = %d", got) | |
| 255 | + | } | |
| 256 | + | if got := 32; got != 32 { | |
| 257 | + | t.Errorf("reply QueryBestSize fixed size = %d", got) | |
| 258 | + | } | |
| 259 | + | if got := 32; got != 32 { | |
| 260 | + | t.Errorf("reply QueryExtension fixed size = %d", got) | |
| 261 | + | } | |
| 262 | + | if got := 32; got != 32 { | |
| 263 | + | t.Errorf("reply ListExtensions fixed size = %d", got) | |
| 264 | + | } | |
| 265 | + | if got := 32; got != 32 { | |
| 266 | + | t.Errorf("reply GetKeyboardMapping fixed size = %d", got) | |
| 267 | + | } | |
| 268 | + | if got := 52; got != 52 { | |
| 269 | + | t.Errorf("reply GetKeyboardControl fixed size = %d", got) | |
| 270 | + | } | |
| 271 | + | if got := 32; got != 32 { | |
| 272 | + | t.Errorf("reply GetPointerControl fixed size = %d", got) | |
| 273 | + | } | |
| 274 | + | if got := 32; got != 32 { | |
| 275 | + | t.Errorf("reply GetScreenSaver fixed size = %d", got) | |
| 276 | + | } | |
| 277 | + | if got := 32; got != 32 { | |
| 278 | + | t.Errorf("reply ListHosts fixed size = %d", got) | |
| 279 | + | } | |
| 280 | + | if got := 32; got != 32 { | |
| 281 | + | t.Errorf("reply SetPointerMapping fixed size = %d", got) | |
| 282 | + | } | |
| 283 | + | if got := 32; got != 32 { | |
| 284 | + | t.Errorf("reply GetPointerMapping fixed size = %d", got) | |
| 285 | + | } | |
| 286 | + | if got := 32; got != 32 { | |
| 287 | + | t.Errorf("reply SetModifierMapping fixed size = %d", got) | |
| 288 | + | } | |
| 289 | + | if got := 32; got != 32 { | |
| 290 | + | t.Errorf("reply GetModifierMapping fixed size = %d", got) | |
| 291 | + | } | |
| 292 | + | ||
| 293 | + | } | |
A xproto/types_generated.go +1353 -0
A xproto/types_test.go +54 -0
Comments4 open / 4
bnema outdated
T2.1 implemented: strict source-located XML AST for all 9 pinned modules, rejection tests, parser fuzz seed. Local make check and CGO_ENABLED=0 go build ./... pass; 3-second parser fuzz run passed (416270 executions). T1.1 is on main (ba4ad52), CI run 221 green, repo public. Stopped before T2.2/T2.3 for a public naming-contract decision: xproto WINDOW xidtype and Window enum both map to Go Window under the specified rules (likewise ATOM/Atom, CURSOR/Cursor, PIXMAP/Pixmap, FONT/Font; render PICTURE/Picture). Should these enums reuse the XID type for constants, or receive a distinct name (please specify the naming rule)? No workaround chosen. T2.4 must wait for T2.2/T2.3; AST preserves expressions, imports, attributes and XML field order. No goldens captured yet.
bnema outdated
T2.2 (85a51dd) and T2.3 are implemented. Applied the decided enum/XID type reuse rule; other declaration collisions are fatal. All nine packages compile; manifest-ordered root ExtIDs, type/struct/union encoders and size checks are generated. Fixed requests include core data-byte handling, negotiated extension major opcodes, padding and sticky-error guards. Full make check passed independently after each task (unfiltered output), CGO-disabled build passed, request/Buf allocation tests passed, and benchmarks show 0 B/op, 0 allocs/op. Local xtrace is glibc execution tracing, so the permitted raw socketpair tee fallback captures independent reference encodings accepted by Xvfb. Three request goldens committed; capture update also passes with race enabled. Decisions: variable structs have owned encoding forms now (borrowed View/Iter APIs remain with list/reply tasks); generation wiring brought forward so gen-check verifies this work. xfixes signatures use render/shape types where the XML imports require them (matching actual wire types). T2.4: extend resolveRequests beyond its explicit list/switch gate, lower AST length expressions with renderExpr, add derived-length and mismatch handling, extend independent capture encoder for InternAtom/ChangeProperty/res.QueryClientIds. Buf already supports aligned reservation, zeroing, sticky errors and growth; transport/ack updates remain Phase 3. CI 222 and 223 green; checking latest run next. Keep this MR draft; do not merge.
bnema outdated
Final verification: CI 224 logs show make check and make xserver passed, as did gen-check. Additional local 10-second parser fuzz run passed (~3.57 million executions); clean CGO_ENABLED=0 go test -count=1 ./... and go build ./... passed. Both signed task commits verified with GPG. Working trees clean, origin is ermite only; MR remains WIP/unmerged.
bnema outdated
T2.4 completed in signed commit 582be88. Full make check and make xserver passed; CGO_ENABLED=0 build passed; independent raw socketpair/Xvfb tee captured InternAtom, ChangeProperty (GetProperty read-back), and XRes QueryClientIds (negotiated XRes 1.2). Race-enabled capture update passed. Allocation tests cover InternAtom, 4 KiB ChangeProperty, and fixed struct lists; all zero. Benchmarks: InternAtom 7.714 ns/op, ChangeProperty4KiB 73.58 ns/op, both 0 B/op and 0 allocs/op. Decisions: support implicit list-name_len refs used by QueryTextExtents only when no explicit field exists; reject derived length truncation with ErrBadLength; bring SendEvent fixed-array signature forward from the explicit public contract. T2.5 should remove the switch gate in resolveRequests and implement typed Values structs/setters; request list sizes/offsets now use running body offsets, with final four-byte rounding. Shared lengths stay explicit (e.g. render AddGlyphs); variable structs use Size/Put. T2.5–T2.8 and T3.1–T3.5 not started; stopping at this clean boundary due to long context. Same branch/worktree, MR draft, no tag.