jsonDecompressTrace decompresses with optional verbose debugging output
(compressed []byte, trace bool)
| 235 | |
| 236 | // jsonDecompressTrace decompresses with optional verbose debugging output |
| 237 | func jsonDecompressTrace(compressed []byte, trace bool) (normal []byte, err error) { |
| 238 | if trace { |
| 239 | fmt.Printf("\n >>> Entering jsonDecompress with %d bytes\n", len(compressed)) |
| 240 | fmt.Printf(" First 16 bytes: % x\n", compressed[:min(len(compressed), 16)]) |
| 241 | } |
| 242 | |
| 243 | // Remove header byte |
| 244 | if len(compressed) == 0 { |
| 245 | err = fmt.Errorf("json decompression error: 0-length data") |
| 246 | if trace { |
| 247 | fmt.Printf(" ERROR: 0-length data\n") |
| 248 | } |
| 249 | return nil, err |
| 250 | } |
| 251 | |
| 252 | compressionType := compressed[0] |
| 253 | if trace { |
| 254 | fmt.Printf(" Compression type: 0x%02x", compressionType) |
| 255 | switch compressionType { |
| 256 | case jc0: |
| 257 | fmt.Printf(" (jc0 - no compression)\n") |
| 258 | case jc1: |
| 259 | fmt.Printf(" (jc1 - JSON string substitution only)\n") |
| 260 | case jc2: |
| 261 | fmt.Printf(" (jc2 - JSON string substitution + Snappy)\n") |
| 262 | case jc3: |
| 263 | fmt.Printf(" (jc3 - Custom subst table + JSON string substitution + Snappy)\n") |
| 264 | default: |
| 265 | fmt.Printf(" (UNKNOWN!)\n") |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | compressed = compressed[1:] |
| 270 | if trace { |
| 271 | fmt.Printf(" After removing header: %d bytes\n", len(compressed)) |
| 272 | } |
| 273 | |
| 274 | // Dispatch based on compression type |
| 275 | if compressionType == jc0 { |
| 276 | normal = compressed |
| 277 | if trace { |
| 278 | fmt.Printf(" No decompression needed, returning %d bytes\n", len(normal)) |
| 279 | fmt.Printf(" <<< Exiting jsonDecompress\n") |
| 280 | } |
| 281 | |
| 282 | // Debug |
| 283 | if debugCompress { |
| 284 | logDebug(context.Background(), "No decompression (%d)", len(normal)) |
| 285 | } |
| 286 | return |
| 287 | } |
| 288 | |
| 289 | if debugCompress { |
| 290 | logDebug(context.Background(), " Removed header byte from %d to %d", len(compressed)+1, len(compressed)) |
| 291 | } |
| 292 | |
| 293 | sdecompressed := compressed |
| 294 | if compressionType == jc1 { |
no test coverage detected