MCPcopy Create free account
hub / github.com/google/gapid / encode

Method encode

core/os/android/binaryxml/string_pool.go:129–170  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

127}
128
129func (c *stringPool) encode() []byte {
130 if len(c.styles) > 0 {
131 panic("TODO: implement style encoding support.")
132 }
133
134 return encodeChunk(resStringPoolType, func(w binary.Writer) {
135 totalHeaderLength := 8 + 5*4 // 8 for the basic header + the five uint32s below
136 w.Uint32(uint32(len(c.strings)))
137 w.Uint32(uint32(len(c.styles)))
138 w.Uint32(c.flags)
139 w.Uint32(uint32(totalHeaderLength + len(c.strings)*4)) // strings start after header and indices
140 w.Uint32(0) // stylesStart
141 }, func(w binary.Writer) {
142 encodedStrings := make([][]byte, len(c.strings))
143 for i, str := range c.strings {
144 encodedStrings[i] = utf16EncodeStringPoolEntry(str)
145 }
146
147 // encode indices
148 index := 0
149 for _, es := range encodedStrings {
150 w.Uint32(uint32(index))
151 index += len(es)
152 }
153 // compute padding (copied logic in bin_xml.py)
154 padding := index % 4
155 if padding == 3 {
156 padding = 1
157 } else if padding == 1 {
158 padding = 3
159 }
160
161 // encode actual strings
162 for _, es := range encodedStrings {
163 w.Data(es)
164 }
165
166 for p := 0; p < padding; p++ {
167 w.Uint8(0)
168 }
169 })
170}
171
172// findFromStringPoolIndex returns a pool reference for the string at the given
173// index in the encoded pool.

Callers

nothing calls this directly

Calls 5

encodeChunkFunction · 0.85
Uint32Method · 0.65
DataMethod · 0.65
Uint8Method · 0.65

Tested by

no test coverage detected