Skip to main content

pdk_script/bindings/
payload.rs

1// Copyright 2023 Salesforce, Inc. All rights reserved.
2use classy::hl::{BodyState, HttpClientResponse, RequestBodyState, ResponseBodyState};
3
4/// Binding for the top-level `payload` variable.
5pub trait PayloadBinding {
6    /// Returns the payload in binary format.
7    fn as_bytes(&self) -> Vec<u8>;
8}
9
10impl PayloadBinding for &[u8] {
11    fn as_bytes(&self) -> Vec<u8> {
12        self.to_vec()
13    }
14}
15
16impl PayloadBinding for RequestBodyState {
17    fn as_bytes(&self) -> Vec<u8> {
18        self.handler().body()
19    }
20}
21
22impl PayloadBinding for ResponseBodyState {
23    fn as_bytes(&self) -> Vec<u8> {
24        self.handler().body()
25    }
26}
27
28impl PayloadBinding for HttpClientResponse {
29    fn as_bytes(&self) -> Vec<u8> {
30        self.body().to_vec()
31    }
32}