Skip to content

Commit d1f712f

Browse files
committed
Use rmp marker types instead of raw MessagePack bytes
Such a better idea in retrospect.
1 parent 090ab51 commit d1f712f

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

benches/criterion.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,31 @@ xt_benchmark! {
118118
}
119119

120120
fn load_medium_data(format: Format) -> Vec<u8> {
121+
use rmp::Marker;
122+
121123
// These manifests were generated using a `helm template` command that should be reproducible
122124
// given the correct version of the original chart.
123125
let input: &[u8] = include_bytes!("k8s-kyverno.yaml");
124126

125127
// For TOML compatibility, we need to take this stream of Kubernetes manifests and put them
126128
// into a single object. Since MessagePack doesn't use characters or indentation for structure,
127129
// it's (surprisingly) the easiest way I can think to do this.
128-
//
129-
// See https://github.com/msgpack/msgpack/blob/master/spec.md for a description of the bytes.
130130
let mut packed = Vec::new();
131131

132-
packed.push(0x81); // Map of 1 element; key and value follow.
132+
packed.push(Marker::FixMap(1).to_u8()); // Map of 1 element; key and value follow.
133133

134-
packed.push(0xa9); // String of 9 characters.
135-
packed.extend(b"manifests");
134+
// Key, string of 9 characters.
135+
let key = b"manifests";
136+
let len = u8::try_from(key.len()).unwrap();
137+
packed.push(Marker::FixStr(len).to_u8());
138+
packed.extend(key);
136139

137-
packed.push(0xdc); // Array; 16-bit size to follow.
138-
packed.extend(79u16.to_be_bytes()); // `xt k8s-kyverno.yaml | jq -s length`
140+
// Array of 79 elements (`xt k8s-kyverno.yaml | jq -s length`); elements follow.
141+
let len: u16 = 79;
142+
packed.push(Marker::Array16.to_u8());
143+
packed.extend(len.to_be_bytes());
139144

140-
// The 79 elements of the array.
145+
// The elements of the array.
141146
xt::translate_slice(input, Some(Format::Yaml), Format::Msgpack, &mut packed)
142147
.expect("k8s-kyverno.yaml should be valid YAML");
143148

0 commit comments

Comments
 (0)