1// Code generated by xtgen; DO NOT EDIT.
2package res
3
4import "encoding/binary"
5
6// QueryVersionReply is a zero-copy view over a QueryVersion 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.
8type QueryVersionReply struct{ raw []byte }
9
10// ParseQueryVersionReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check.
11func ParseQueryVersionReply(raw []byte) (QueryVersionReply, bool) {
12 if len(raw) < 32 {
13 return QueryVersionReply{}, false
14 }
15 r := QueryVersionReply{raw: raw}
16 return r, true
17}
18func (r QueryVersionReply) Raw() []byte { return r.raw }
19func (r QueryVersionReply) ServerMajor() uint16 { return uint16(binary.LittleEndian.Uint16(r.raw[8:])) }
20func (r QueryVersionReply) ServerMinor() uint16 {
21 return uint16(binary.LittleEndian.Uint16(r.raw[10:]))
22}
23
24// QueryClientsReply is a zero-copy view over a QueryClients reply; offsets count from reply byte 0.
25// It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep.
26type QueryClientsReply struct{ raw []byte }
27
28// ParseQueryClientsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check.
29func ParseQueryClientsReply(raw []byte) (QueryClientsReply, bool) {
30 if len(raw) < 32 {
31 return QueryClientsReply{}, false
32 }
33 r := QueryClientsReply{raw: raw}
34 off := 32
35 {
36 n := int(r.NumClients())
37 if n < 0 || n > len(r.raw) {
38 return QueryClientsReply{}, false
39 }
40 off += n * 8
41 }
42 if off > len(r.raw) {
43 return QueryClientsReply{}, false
44 }
45 if off > len(r.raw) {
46 return QueryClientsReply{}, false
47 }
48 return r, true
49}
50func (r QueryClientsReply) Raw() []byte { return r.raw }
51func (r QueryClientsReply) NumClients() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[8:])) }
52func (r QueryClientsReply) Clients() ClientList {
53 off := 32
54 end := off + (int(r.NumClients()))*8
55 return ClientList{b: r.raw[off:end:end]}
56}
57
58// QueryClientResourcesReply is a zero-copy view over a QueryClientResources reply; offsets count from reply byte 0.
59// It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep.
60type QueryClientResourcesReply struct{ raw []byte }
61
62// ParseQueryClientResourcesReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check.
63func ParseQueryClientResourcesReply(raw []byte) (QueryClientResourcesReply, bool) {
64 if len(raw) < 32 {
65 return QueryClientResourcesReply{}, false
66 }
67 r := QueryClientResourcesReply{raw: raw}
68 off := 32
69 {
70 n := int(r.NumTypes())
71 if n < 0 || n > len(r.raw) {
72 return QueryClientResourcesReply{}, false
73 }
74 off += n * 8
75 }
76 if off > len(r.raw) {
77 return QueryClientResourcesReply{}, false
78 }
79 if off > len(r.raw) {
80 return QueryClientResourcesReply{}, false
81 }
82 return r, true
83}
84func (r QueryClientResourcesReply) Raw() []byte { return r.raw }
85func (r QueryClientResourcesReply) NumTypes() uint32 {
86 return uint32(binary.LittleEndian.Uint32(r.raw[8:]))
87}
88func (r QueryClientResourcesReply) Types() TypeList {
89 off := 32
90 end := off + (int(r.NumTypes()))*8
91 return TypeList{b: r.raw[off:end:end]}
92}
93
94// QueryClientPixmapBytesReply is a zero-copy view over a QueryClientPixmapBytes reply; offsets count from reply byte 0.
95// It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep.
96type QueryClientPixmapBytesReply struct{ raw []byte }
97
98// ParseQueryClientPixmapBytesReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check.
99func ParseQueryClientPixmapBytesReply(raw []byte) (QueryClientPixmapBytesReply, bool) {
100 if len(raw) < 32 {
101 return QueryClientPixmapBytesReply{}, false
102 }
103 r := QueryClientPixmapBytesReply{raw: raw}
104 return r, true
105}
106func (r QueryClientPixmapBytesReply) Raw() []byte { return r.raw }
107func (r QueryClientPixmapBytesReply) Bytes() uint32 {
108 return uint32(binary.LittleEndian.Uint32(r.raw[8:]))
109}
110func (r QueryClientPixmapBytesReply) BytesOverflow() uint32 {
111 return uint32(binary.LittleEndian.Uint32(r.raw[12:]))
112}
113
114// QueryClientIdsReply is a zero-copy view over a QueryClientIds reply; offsets count from reply byte 0.
115// It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep.
116type QueryClientIdsReply struct{ raw []byte }
117
118// ParseQueryClientIdsReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check.
119func ParseQueryClientIdsReply(raw []byte) (QueryClientIdsReply, bool) {
120 if len(raw) < 32 {
121 return QueryClientIdsReply{}, false
122 }
123 r := QueryClientIdsReply{raw: raw}
124 off := 32
125 {
126 n := int(r.NumIds())
127 if off > len(r.raw) || n < 0 || n > len(r.raw) {
128 return QueryClientIdsReply{}, false
129 }
130 it := NewClientIdValueIter(r.raw[off:], n)
131 for it.Next() {
132 off += it.Value().Size()
133 }
134 if it.Err() {
135 return QueryClientIdsReply{}, false
136 }
137 }
138 if off > len(r.raw) {
139 return QueryClientIdsReply{}, false
140 }
141 return r, true
142}
143func (r QueryClientIdsReply) Raw() []byte { return r.raw }
144func (r QueryClientIdsReply) NumIds() uint32 { return uint32(binary.LittleEndian.Uint32(r.raw[8:])) }
145func (r QueryClientIdsReply) Ids() ClientIdValueIter {
146 off := 32
147 return NewClientIdValueIter(r.raw[off:], int(r.NumIds()))
148}
149
150// QueryResourceBytesReply is a zero-copy view over a QueryResourceBytes reply; offsets count from reply byte 0.
151// It borrows the reply bytes: valid only until the Handler callback returns, because the read ring is reused. Copy what you keep.
152type QueryResourceBytesReply struct{ raw []byte }
153
154// ParseQueryResourceBytesReply validates raw (the whole reply, 32+4*length bytes) once; getters do not re-check.
155func ParseQueryResourceBytesReply(raw []byte) (QueryResourceBytesReply, bool) {
156 if len(raw) < 32 {
157 return QueryResourceBytesReply{}, false
158 }
159 r := QueryResourceBytesReply{raw: raw}
160 off := 32
161 {
162 n := int(r.NumSizes())
163 if off > len(r.raw) || n < 0 || n > len(r.raw) {
164 return QueryResourceBytesReply{}, false
165 }
166 it := NewResourceSizeValueIter(r.raw[off:], n)
167 for it.Next() {
168 off += it.Value().Size()
169 }
170 if it.Err() {
171 return QueryResourceBytesReply{}, false
172 }
173 }
174 if off > len(r.raw) {
175 return QueryResourceBytesReply{}, false
176 }
177 return r, true
178}
179func (r QueryResourceBytesReply) Raw() []byte { return r.raw }
180func (r QueryResourceBytesReply) NumSizes() uint32 {
181 return uint32(binary.LittleEndian.Uint32(r.raw[8:]))
182}
183func (r QueryResourceBytesReply) Sizes() ResourceSizeValueIter {
184 off := 32
185 return NewResourceSizeValueIter(r.raw[off:], int(r.NumSizes()))
186}
187
188// ClientIdValueView is a zero-copy view over one wire-encoded ClientIdValue, yielded by ClientIdValueIter.
189// It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep.
190type ClientIdValueView struct{ raw []byte }
191
192func (v ClientIdValueView) Raw() []byte { return v.raw }
193
194// Size is the element's wire size, including trailing alignment.
195func (v ClientIdValueView) Size() int { return len(v.raw) }
196func sizeClientIdValue(p []byte) int {
197 if len(p) < 12 {
198 return -1
199 }
200 v := ClientIdValueView{raw: p}
201 _ = v
202 off := 12
203 {
204 n := (int(v.Length()) / 4)
205 if n < 0 || n > len(v.raw) {
206 return -1
207 }
208 off += n * 4
209 }
210 if off > len(v.raw) {
211 return -1
212 }
213 if off > len(v.raw) {
214 return -1
215 }
216 return off
217}
218func (v ClientIdValueView) Spec() ClientIdSpec { return GetClientIdSpec(v.raw[0:]) }
219func (v ClientIdValueView) Length() uint32 { return uint32(binary.LittleEndian.Uint32(v.raw[8:])) }
220func (v ClientIdValueView) Value() Uint32List {
221 off := 12
222 end := off + (int(v.Length())/4)*4
223 return Uint32List{b: v.raw[off:end:end]}
224}
225
226// ClientIdValueIter walks n consecutive ClientIdValue elements; Err reports a malformed length.
227// It shares the lifetime of the bytes it walks.
228type ClientIdValueIter struct {
229 b []byte
230 n int
231 v ClientIdValueView
232 err bool
233}
234
235// NewClientIdValueIter iterates n elements encoded at the start of b.
236func NewClientIdValueIter(b []byte, n int) ClientIdValueIter { return ClientIdValueIter{b: b, n: n} }
237func (it *ClientIdValueIter) Next() bool {
238 if it.n <= 0 || it.err {
239 return false
240 }
241 s := sizeClientIdValue(it.b)
242 if s < 0 {
243 it.err = true
244 it.n = 0
245 return false
246 }
247 it.v = ClientIdValueView{raw: it.b[:s:s]}
248 it.b = it.b[s:]
249 it.n--
250 return true
251}
252func (it *ClientIdValueIter) Value() ClientIdValueView { return it.v }
253func (it *ClientIdValueIter) Err() bool { return it.err }
254
255// ResourceSizeValueView is a zero-copy view over one wire-encoded ResourceSizeValue, yielded by ResourceSizeValueIter.
256// It shares the lifetime of the bytes it was taken from (for replies: until the Handler callback returns). Copy what you keep.
257type ResourceSizeValueView struct{ raw []byte }
258
259func (v ResourceSizeValueView) Raw() []byte { return v.raw }
260
261// Size is the element's wire size, including trailing alignment.
262func (v ResourceSizeValueView) Size() int { return len(v.raw) }
263func sizeResourceSizeValue(p []byte) int {
264 if len(p) < 24 {
265 return -1
266 }
267 v := ResourceSizeValueView{raw: p}
268 _ = v
269 off := 24
270 {
271 n := int(v.NumCrossReferences())
272 if n < 0 || n > len(v.raw) {
273 return -1
274 }
275 off += n * 20
276 }
277 if off > len(v.raw) {
278 return -1
279 }
280 if off > len(v.raw) {
281 return -1
282 }
283 return off
284}
285func (v ResourceSizeValueView) Size_() ResourceSizeSpec { return GetResourceSizeSpec(v.raw[0:]) }
286func (v ResourceSizeValueView) NumCrossReferences() uint32 {
287 return uint32(binary.LittleEndian.Uint32(v.raw[20:]))
288}
289func (v ResourceSizeValueView) CrossReferences() ResourceSizeSpecList {
290 off := 24
291 end := off + (int(v.NumCrossReferences()))*20
292 return ResourceSizeSpecList{b: v.raw[off:end:end]}
293}
294
295// ResourceSizeValueIter walks n consecutive ResourceSizeValue elements; Err reports a malformed length.
296// It shares the lifetime of the bytes it walks.
297type ResourceSizeValueIter struct {
298 b []byte
299 n int
300 v ResourceSizeValueView
301 err bool
302}
303
304// NewResourceSizeValueIter iterates n elements encoded at the start of b.
305func NewResourceSizeValueIter(b []byte, n int) ResourceSizeValueIter {
306 return ResourceSizeValueIter{b: b, n: n}
307}
308func (it *ResourceSizeValueIter) Next() bool {
309 if it.n <= 0 || it.err {
310 return false
311 }
312 s := sizeResourceSizeValue(it.b)
313 if s < 0 {
314 it.err = true
315 it.n = 0
316 return false
317 }
318 it.v = ResourceSizeValueView{raw: it.b[:s:s]}
319 it.b = it.b[s:]
320 it.n--
321 return true
322}
323func (it *ResourceSizeValueIter) Value() ResourceSizeValueView { return it.v }
324func (it *ResourceSizeValueIter) Err() bool { return it.err }
325
326// ClientList is a borrowed view over a wire list of Client. It shares the lifetime of the bytes it was taken from; copy what you keep.
327type ClientList struct{ b []byte }
328
329func (l ClientList) Len() int { return len(l.b) / 8 }
330func (l ClientList) At(i int) Client { return GetClient(l.b[i*8:]) }
331
332// ResourceSizeSpecList is a borrowed view over a wire list of ResourceSizeSpec. It shares the lifetime of the bytes it was taken from; copy what you keep.
333type ResourceSizeSpecList struct{ b []byte }
334
335func (l ResourceSizeSpecList) Len() int { return len(l.b) / 20 }
336func (l ResourceSizeSpecList) At(i int) ResourceSizeSpec { return GetResourceSizeSpec(l.b[i*20:]) }
337
338// TypeList is a borrowed view over a wire list of Type. It shares the lifetime of the bytes it was taken from; copy what you keep.
339type TypeList struct{ b []byte }
340
341func (l TypeList) Len() int { return len(l.b) / 8 }
342func (l TypeList) At(i int) Type { return GetType(l.b[i*8:]) }
343
344// 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.
345type Uint32List struct{ b []byte }
346
347func (l Uint32List) Len() int { return len(l.b) / 4 }
348func (l Uint32List) At(i int) uint32 { return uint32(binary.LittleEndian.Uint32(l.b[i*4:])) }