| 210 | } |
| 211 | |
| 212 | pub fn slice_from_proto(slice: &pb::SandboxSlice) -> Result<SandboxSlice, String> { |
| 213 | let spans = slice |
| 214 | .content_spans |
| 215 | .iter() |
| 216 | .map(|span| { |
| 217 | if span.length != span.content.len() as u64 { |
| 218 | return Err(format!( |
| 219 | "a span says {} bytes and carries {}", |
| 220 | span.length, |
| 221 | span.content.len() |
| 222 | )); |
| 223 | } |
| 224 | Ok(SpanBytes { |
| 225 | change: hash_from_proto(span.change.as_ref())?, |
| 226 | start: span.offset, |
| 227 | bytes: span.content.clone(), |
| 228 | }) |
| 229 | }) |
| 230 | .collect::<Result<Vec<_>, String>>()?; |
| 231 | SandboxSlice::from_parts( |
| 232 | payload(slice.graph_slice.as_ref(), SANDBOX_GRAPH_SLICE_SCHEMA)?, |
| 233 | spans, |
| 234 | ) |
| 235 | .map_err(|e| e.to_string()) |
| 236 | } |
| 237 | |
| 238 | /// A refusal as the contract's [`pb::ErrorInfo`]: `VIEW_STALE` for a stale |
| 239 | /// view, `CHANGE_REJECTED` otherwise, with the variant in |