// Code generated by xtgen; DO NOT EDIT. package render import "bnema.dev/xturbo/xproto" import "encoding/binary" // QueryVersionReply is a zero-copy view over a QueryVersion reply; offsets count from reply byte 0. // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. type QueryVersionReply struct{ raw []byte } // ParseQueryVersionReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. func ParseQueryVersionReply(raw []byte) (QueryVersionReply, bool) { if len(raw) < 32 { return QueryVersionReply{}, false } r := QueryVersionReply{raw: raw} return r, true } func (r QueryVersionReply) Raw() []byte { return r.raw } func (r QueryVersionReply) MajorVersion() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[8:])) } func (r QueryVersionReply) MinorVersion() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[12:])) } // QueryPictFormatsReply is a zero-copy view over a QueryPictFormats reply; offsets count from reply byte 0. // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. type QueryPictFormatsReply struct{ raw []byte } // ParseQueryPictFormatsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. func ParseQueryPictFormatsReply(raw []byte) (QueryPictFormatsReply, bool) { if len(raw) < 32 { return QueryPictFormatsReply{}, false } r := QueryPictFormatsReply{raw: raw} off := 32 { n := int(r.NumFormats()) if n < 0 || n > len(r.raw) { return QueryPictFormatsReply{}, false } off += n * 28 } if off > len(r.raw) { return QueryPictFormatsReply{}, false } { n := int(r.NumScreens()) if off > len(r.raw) || n < 0 || n > len(r.raw) { return QueryPictFormatsReply{}, false } it := NewPictscreenIter(r.raw[off:], n) for it.Next() { off += it.Value().Size() } if it.Err() { return QueryPictFormatsReply{}, false } } { n := int(r.NumSubpixel()) if n < 0 || n > len(r.raw) { return QueryPictFormatsReply{}, false } off += n * 4 } if off > len(r.raw) { return QueryPictFormatsReply{}, false } if off > len(r.raw) { return QueryPictFormatsReply{}, false } return r, true } func (r QueryPictFormatsReply) Raw() []byte { return r.raw } func (r QueryPictFormatsReply) NumFormats() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[8:])) } func (r QueryPictFormatsReply) NumScreens() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[12:])) } func (r QueryPictFormatsReply) NumDepths() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[16:])) } func (r QueryPictFormatsReply) NumVisuals() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[20:])) } func (r QueryPictFormatsReply) NumSubpixel() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[24:])) } func (r QueryPictFormatsReply) Formats() PictforminfoList { off := 32 end := off + (int(r.NumFormats()))*28 return PictforminfoList{b: r.raw[off:end:end]} } func (r QueryPictFormatsReply) Screens() PictscreenIter { off := 32 { n := int(r.NumFormats()) off += n * 28 } return NewPictscreenIter(r.raw[off:], int(r.NumScreens())) } func (r QueryPictFormatsReply) Subpixels() SubPixelList { off := 32 { n := int(r.NumFormats()) off += n * 28 } { n := int(r.NumScreens()) it := NewPictscreenIter(r.raw[off:], n) for it.Next() { off += it.Value().Size() } } end := off + (int(r.NumSubpixel()))*4 return SubPixelList{b: r.raw[off:end:end]} } // QueryPictIndexValuesReply is a zero-copy view over a QueryPictIndexValues reply; offsets count from reply byte 0. // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. type QueryPictIndexValuesReply struct{ raw []byte } // ParseQueryPictIndexValuesReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. func ParseQueryPictIndexValuesReply(raw []byte) (QueryPictIndexValuesReply, bool) { if len(raw) < 32 { return QueryPictIndexValuesReply{}, false } r := QueryPictIndexValuesReply{raw: raw} off := 32 { n := int(r.NumValues()) if n < 0 || n > len(r.raw) { return QueryPictIndexValuesReply{}, false } off += n * 12 } if off > len(r.raw) { return QueryPictIndexValuesReply{}, false } if off > len(r.raw) { return QueryPictIndexValuesReply{}, false } return r, true } func (r QueryPictIndexValuesReply) Raw() []byte { return r.raw } func (r QueryPictIndexValuesReply) NumValues() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[8:])) } func (r QueryPictIndexValuesReply) Values() IndexvalueList { off := 32 end := off + (int(r.NumValues()))*12 return IndexvalueList{b: r.raw[off:end:end]} } // QueryFiltersReply is a zero-copy view over a QueryFilters reply; offsets count from reply byte 0. // It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep. type QueryFiltersReply struct{ raw []byte } // ParseQueryFiltersReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check. func ParseQueryFiltersReply(raw []byte) (QueryFiltersReply, bool) { if len(raw) < 32 { return QueryFiltersReply{}, false } r := QueryFiltersReply{raw: raw} off := 32 { n := int(r.NumAliases()) if n < 0 || n > len(r.raw) { return QueryFiltersReply{}, false } off += n * 2 } if off > len(r.raw) { return QueryFiltersReply{}, false } { n := int(r.NumFilters()) if off > len(r.raw) || n < 0 || n > len(r.raw) { return QueryFiltersReply{}, false } it := xproto.NewStrIter(r.raw[off:], n) for it.Next() { off += it.Value().Size() } if it.Err() { return QueryFiltersReply{}, false } } if off > len(r.raw) { return QueryFiltersReply{}, false } return r, true } func (r QueryFiltersReply) Raw() []byte { return r.raw } func (r QueryFiltersReply) NumAliases() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[8:])) } func (r QueryFiltersReply) NumFilters() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[12:])) } func (r QueryFiltersReply) Aliases() Uint16List { off := 32 end := off + (int(r.NumAliases()))*2 return Uint16List{b: r.raw[off:end:end]} } func (r QueryFiltersReply) Filters() xproto.StrIter { off := 32 { n := int(r.NumAliases()) off += n * 2 } return xproto.NewStrIter(r.raw[off:], int(r.NumFilters())) } // PictdepthView is a zero-copy view over one wire-encoded Pictdepth, yielded by PictdepthIter. // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. type PictdepthView struct{ raw []byte } func (v PictdepthView) Raw() []byte { return v.raw } // Size is the element's wire size, including trailing alignment. func (v PictdepthView) Size() int { return len(v.raw) } func sizePictdepth(p []byte) int { if len(p) < 8 { return -1 } v := PictdepthView{raw: p} _ = v off := 8 { n := int(v.NumVisuals()) if n < 0 || n > len(v.raw) { return -1 } off += n * 8 } if off > len(v.raw) { return -1 } if off > len(v.raw) { return -1 } return off } func (v PictdepthView) Depth() uint8 { return uint8(v.raw[0:][0]) } func (v PictdepthView) NumVisuals() uint16 { return uint16(binary.LittleEndian.Uint16(v.raw[2:])) } func (v PictdepthView) Visuals() PictvisualList { off := 8 end := off + (int(v.NumVisuals()))*8 return PictvisualList{b: v.raw[off:end:end]} } // PictdepthIter walks n consecutive Pictdepth elements; Err reports a malformed length. // It shares the lifetime of the bytes it walks. type PictdepthIter struct { b []byte n int v PictdepthView err bool } // NewPictdepthIter iterates n elements encoded at the start of b. func NewPictdepthIter(b []byte, n int) PictdepthIter { return PictdepthIter{b: b, n: n} } func (it *PictdepthIter) Next() bool { if it.n <= 0 || it.err { return false } s := sizePictdepth(it.b) if s < 0 { it.err = true it.n = 0 return false } it.v = PictdepthView{raw: it.b[:s:s]} it.b = it.b[s:] it.n-- return true } func (it *PictdepthIter) Value() PictdepthView { return it.v } func (it *PictdepthIter) Err() bool { return it.err } // PictscreenView is a zero-copy view over one wire-encoded Pictscreen, yielded by PictscreenIter. // It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep. type PictscreenView struct{ raw []byte } func (v PictscreenView) Raw() []byte { return v.raw } // Size is the element's wire size, including trailing alignment. func (v PictscreenView) Size() int { return len(v.raw) } func sizePictscreen(p []byte) int { if len(p) < 8 { return -1 } v := PictscreenView{raw: p} _ = v off := 8 { n := int(v.NumDepths()) if off > len(v.raw) || n < 0 || n > len(v.raw) { return -1 } it := NewPictdepthIter(v.raw[off:], n) for it.Next() { off += it.Value().Size() } if it.Err() { return -1 } } if off > len(v.raw) { return -1 } return off } func (v PictscreenView) NumDepths() uint32 { return uint32(binary.LittleEndian.Uint32(v.raw[0:])) } func (v PictscreenView) Fallback() Pictformat { return Pictformat(binary.LittleEndian.Uint32(v.raw[4:])) } func (v PictscreenView) Depths() PictdepthIter { off := 8 return NewPictdepthIter(v.raw[off:], int(v.NumDepths())) } // PictscreenIter walks n consecutive Pictscreen elements; Err reports a malformed length. // It shares the lifetime of the bytes it walks. type PictscreenIter struct { b []byte n int v PictscreenView err bool } // NewPictscreenIter iterates n elements encoded at the start of b. func NewPictscreenIter(b []byte, n int) PictscreenIter { return PictscreenIter{b: b, n: n} } func (it *PictscreenIter) Next() bool { if it.n <= 0 || it.err { return false } s := sizePictscreen(it.b) if s < 0 { it.err = true it.n = 0 return false } it.v = PictscreenView{raw: it.b[:s:s]} it.b = it.b[s:] it.n-- return true } func (it *PictscreenIter) Value() PictscreenView { return it.v } func (it *PictscreenIter) Err() bool { return it.err } // IndexvalueList is a borrowed view over a wire list of Indexvalue. It shares the lifetime of the bytes it was taken from; copy what you keep. type IndexvalueList struct{ b []byte } func (l IndexvalueList) Len() int { return len(l.b) / 12 } func (l IndexvalueList) At(i int) Indexvalue { return GetIndexvalue(l.b[i*12:]) } // PictforminfoList is a borrowed view over a wire list of Pictforminfo. It shares the lifetime of the bytes it was taken from; copy what you keep. type PictforminfoList struct{ b []byte } func (l PictforminfoList) Len() int { return len(l.b) / 28 } func (l PictforminfoList) At(i int) Pictforminfo { return GetPictforminfo(l.b[i*28:]) } // PictvisualList is a borrowed view over a wire list of Pictvisual. It shares the lifetime of the bytes it was taken from; copy what you keep. type PictvisualList struct{ b []byte } func (l PictvisualList) Len() int { return len(l.b) / 8 } func (l PictvisualList) At(i int) Pictvisual { return GetPictvisual(l.b[i*8:]) } // SubPixelList is a borrowed view over a wire list of SubPixel. It shares the lifetime of the bytes it was taken from; copy what you keep. type SubPixelList struct{ b []byte } func (l SubPixelList) Len() int { return len(l.b) / 4 } func (l SubPixelList) At(i int) SubPixel { return SubPixel(binary.LittleEndian.Uint32(l.b[i*4:])) } // Uint16List is a borrowed view over a wire list of uint16. It shares the lifetime of the bytes it was taken from; copy what you keep. type Uint16List struct{ b []byte } func (l Uint16List) Len() int { return len(l.b) / 2 } func (l Uint16List) At(i int) uint16 { return uint16(binary.LittleEndian.Uint16(l.b[i*2:])) }