MCPcopy
hub / github.com/klauspost/compress / decodeLiterals

Method decodeLiterals

zstd/blockdec.go:275–474  ·  view source on GitHub ↗
(in []byte, hist *history)

Source from the content-addressed store, hash-verified

273}
274
275func (b *blockDec) decodeLiterals(in []byte, hist *history) (remain []byte, err error) {
276 // There must be at least one byte for Literals_Block_Type and one for Sequences_Section_Header
277 if len(in) < 2 {
278 return in, ErrBlockTooSmall
279 }
280
281 litType := literalsBlockType(in[0] & 3)
282 var litRegenSize int
283 var litCompSize int
284 sizeFormat := (in[0] >> 2) & 3
285 var fourStreams bool
286 var literals []byte
287 switch litType {
288 case literalsBlockRaw, literalsBlockRLE:
289 switch sizeFormat {
290 case 0, 2:
291 // Regenerated_Size uses 5 bits (0-31). Literals_Section_Header uses 1 byte.
292 litRegenSize = int(in[0] >> 3)
293 in = in[1:]
294 case 1:
295 // Regenerated_Size uses 12 bits (0-4095). Literals_Section_Header uses 2 bytes.
296 litRegenSize = int(in[0]>>4) + (int(in[1]) << 4)
297 in = in[2:]
298 case 3:
299 // Regenerated_Size uses 20 bits (0-1048575). Literals_Section_Header uses 3 bytes.
300 if len(in) < 3 {
301 println("too small: litType:", litType, " sizeFormat", sizeFormat, len(in))
302 return in, ErrBlockTooSmall
303 }
304 litRegenSize = int(in[0]>>4) + (int(in[1]) << 4) + (int(in[2]) << 12)
305 in = in[3:]
306 }
307 case literalsBlockCompressed, literalsBlockTreeless:
308 switch sizeFormat {
309 case 0, 1:
310 // Both Regenerated_Size and Compressed_Size use 10 bits (0-1023).
311 if len(in) < 3 {
312 println("too small: litType:", litType, " sizeFormat", sizeFormat, len(in))
313 return in, ErrBlockTooSmall
314 }
315 n := uint64(in[0]>>4) + (uint64(in[1]) << 4) + (uint64(in[2]) << 12)
316 litRegenSize = int(n & 1023)
317 litCompSize = int(n >> 10)
318 fourStreams = sizeFormat == 1
319 in = in[3:]
320 case 2:
321 fourStreams = true
322 if len(in) < 4 {
323 println("too small: litType:", litType, " sizeFormat", sizeFormat, len(in))
324 return in, ErrBlockTooSmall
325 }
326 n := uint64(in[0]>>4) + (uint64(in[1]) << 4) + (uint64(in[2]) << 12) + (uint64(in[3]) << 20)
327 litRegenSize = int(n & 16383)
328 litCompSize = int(n >> 14)
329 in = in[4:]
330 case 3:
331 fourStreams = true
332 if len(in) < 5 {

Callers 2

decodeCompressedMethod · 0.95
startStreamDecoderMethod · 0.80

Calls 7

ReadTableFunction · 0.92
literalsBlockTypeTypeAlias · 0.85
printlnFunction · 0.85
printfFunction · 0.85
DecoderMethod · 0.80
Decompress4XMethod · 0.45
Decompress1XMethod · 0.45

Tested by

no test coverage detected