1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Failure blobs: a portable, copy-pasteable reproducer for a failing test
// case — a base64 string encoding its choice sequence.
//
// A blob encodes the *choice sequence* of a (usually minimal) failing test
// case so it can be replayed deterministically — pasted into a
// `#[hegel::reproduce_failure("…")]` attribute, fed to
// `Hegel::reproduce_failure`, or handed across the C ABI.
//
// # Format
//
// base64( prefix_byte ++ payload )
//
// where `payload` is [`serialize_choices`] of the choice sequence and the
// `prefix_byte` selects how it is stored:
//
// - `0` (`PREFIX_RAW`): `payload` is the raw `serialize_choices` bytes.
// - `1` (`PREFIX_ZLIB`): `payload` is the zlib compression of those bytes.
//
// [`encode_failure`] computes both and keeps whichever is shorter — for the
// tiny choice sequences a shrunk counterexample usually has, the zlib header
// overhead loses and the raw form wins (so most blobs carry prefix `0`); for
// large sequences the compressed form wins. The inner `serialize_choices`
// encoding (see [`crate::native::database`]) is Hegel's own, so it is only
/// guaranteed to reproduce a failure within a specific version of Hegel.
//
// [`decode_failure`] reverses every step and returns `None` on *any*
// malformation (bad base64, unknown prefix byte, corrupt zlib stream, or a
// payload [`deserialize_choices`] rejects). Callers treat `None` as "this
// blob can't be replayed" and panic.
use crate;
use crateChoiceValue;
use crate;
/// `payload` is the raw [`serialize_choices`] output.
const PREFIX_RAW: u8 = 0;
/// `payload` is the zlib compression of the [`serialize_choices`] output.
const PREFIX_ZLIB: u8 = 1;
/// zlib compression level used by [`encode_failure`]. 6 is the zlib default.
const ZLIB_LEVEL: u8 = 6;
/// Encode a choice sequence into a failure blob (see the module docs for the
/// format). The returned string is safe to embed in source as a string
/// literal and to round-trip through [`decode_failure`].
/// Decode a failure blob produced by [`encode_failure`] back into a choice
/// sequence, or `None` if the blob is malformed, truncated, compressed with a
/// corrupt stream, carries an unknown prefix byte, or decodes to bytes
/// [`deserialize_choices`] rejects.