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

Function encodeChunk

core/os/android/binaryxml/decode.go:171–189  ·  view source on GitHub ↗

encodeChunk takes functions that output chunk-specific header and data to a writer, and then uses them to compute header and chunk sizes, as well as writing the whole chunk to a byte array, which is then returned.

(chunkType uint16, headerf func(w binary.Writer), dataf func(w binary.Writer))

Source from the content-addressed store, hash-verified

169// encodeChunk takes functions that output chunk-specific header and data to a writer, and then uses them to
170// compute header and chunk sizes, as well as writing the whole chunk to a byte array, which is then returned.
171func encodeChunk(chunkType uint16, headerf func(w binary.Writer), dataf func(w binary.Writer)) []byte {
172 var headerBuffer bytes.Buffer
173 headerf(endian.Writer(&headerBuffer, device.LittleEndian))
174 headerBytes := headerBuffer.Bytes()
175
176 var dataBuffer bytes.Buffer
177 dataf(endian.Writer(&dataBuffer, device.LittleEndian))
178 dataBytes := dataBuffer.Bytes()
179
180 var chunkBuffer bytes.Buffer
181 w := endian.Writer(&chunkBuffer, device.LittleEndian)
182 w.Uint16(chunkType)
183 w.Uint16(uint16(len(headerBytes) + 8))
184 w.Uint32(uint32(len(headerBytes) + len(dataBytes) + 8))
185 w.Data(headerBytes)
186 w.Data(dataBytes)
187
188 return chunkBuffer.Bytes()
189}

Callers 8

encodeMethod · 0.85
encodeMethod · 0.85
encodeMethod · 0.85
encodeMethod · 0.85
encodeMethod · 0.85
encodeMethod · 0.85
encodeMethod · 0.85
encodeMethod · 0.85

Calls 4

WriterMethod · 0.80
Uint16Method · 0.65
Uint32Method · 0.65
DataMethod · 0.65

Tested by

no test coverage detected