pdk_script/bindings/
payload.rs

1// Copyright (c) 2025, Salesforce, Inc.,
2// All rights reserved.
3// For full license text, see the LICENSE.txt file
4
5use classy::hl::{BodyState, HttpClientResponse, RequestBodyState, ResponseBodyState};
6
7#[cfg(feature = "experimental_enable_stop_iteration")]
8use classy::hl::{HeadersBodyState, RequestHeadersBodyState, ResponseHeadersBodyState};
9
10/// Binding for the top-level `payload` variable.
11pub trait PayloadBinding {
12    /// Returns the payload in binary format.
13    fn as_bytes(&self) -> Vec<u8>;
14}
15
16impl PayloadBinding for &[u8] {
17    fn as_bytes(&self) -> Vec<u8> {
18        self.to_vec()
19    }
20}
21
22impl PayloadBinding for String {
23    fn as_bytes(&self) -> Vec<u8> {
24        self.as_bytes().to_vec()
25    }
26}
27
28impl PayloadBinding for RequestBodyState {
29    fn as_bytes(&self) -> Vec<u8> {
30        self.handler().body()
31    }
32}
33
34#[cfg(feature = "experimental_enable_stop_iteration")]
35impl PayloadBinding for RequestHeadersBodyState {
36    fn as_bytes(&self) -> Vec<u8> {
37        self.handler().body()
38    }
39}
40
41impl PayloadBinding for ResponseBodyState {
42    fn as_bytes(&self) -> Vec<u8> {
43        self.handler().body()
44    }
45}
46
47#[cfg(feature = "experimental_enable_stop_iteration")]
48impl PayloadBinding for ResponseHeadersBodyState {
49    fn as_bytes(&self) -> Vec<u8> {
50        self.handler().body()
51    }
52}
53
54impl PayloadBinding for HttpClientResponse {
55    fn as_bytes(&self) -> Vec<u8> {
56        self.body().to_vec()
57    }
58}