|
62 | 62 | //! # use datafusion_proto_common::protobuf_common; |
63 | 63 | //! # use prost::Message; |
64 | 64 | //! # fn main() -> Result<()>{ |
65 | | -//! // Create a new ScalarValue |
66 | | -//! let val = ScalarValue::UInt64(Some(3)); |
67 | | -//! let mut buffer = BytesMut::new(); |
68 | | -//! let protobuf: protobuf_common::ScalarValue = match val { |
69 | | -//! ScalarValue::UInt64(Some(val)) => { |
70 | | -//! protobuf_common::ScalarValue{value: Some(protobuf_common::scalar_value::Value::Uint64Value(val))} |
71 | | -//! } |
72 | | -//! _ => unreachable!(), |
73 | | -//! }; |
| 65 | +//! // Create a new ScalarValue |
| 66 | +//! let val = ScalarValue::UInt64(Some(3)); |
| 67 | +//! let mut buffer = BytesMut::new(); |
| 68 | +//! let protobuf: protobuf_common::ScalarValue = match val { |
| 69 | +//! ScalarValue::UInt64(Some(val)) => protobuf_common::ScalarValue { |
| 70 | +//! value: Some(protobuf_common::scalar_value::Value::Uint64Value(val)), |
| 71 | +//! }, |
| 72 | +//! _ => unreachable!(), |
| 73 | +//! }; |
74 | 74 | //! |
75 | | -//! protobuf.encode(&mut buffer) |
| 75 | +//! protobuf |
| 76 | +//! .encode(&mut buffer) |
76 | 77 | //! .map_err(|e| plan_datafusion_err!("Error encoding protobuf as bytes: {e}"))?; |
77 | | -//! // Convert it to bytes (for sending over the network, etc.) |
78 | | -//! let bytes: Bytes = buffer.into(); |
| 78 | +//! // Convert it to bytes (for sending over the network, etc.) |
| 79 | +//! let bytes: Bytes = buffer.into(); |
79 | 80 | //! |
80 | | -//! let protobuf = protobuf_common::ScalarValue::decode(bytes).map_err(|e| plan_datafusion_err!("Error decoding ScalarValue as protobuf: {e}"))?; |
81 | | -//! // Decode bytes from somewhere (over network, etc.) back to ScalarValue |
82 | | -//! let decoded_val: ScalarValue = match protobuf.value { |
83 | | -//! Some(protobuf_common::scalar_value::Value::Uint64Value(val)) => ScalarValue::UInt64(Some(val)), |
84 | | -//! _ => unreachable!(), |
85 | | -//! }; |
86 | | -//! assert_eq!(val, decoded_val); |
| 81 | +//! let protobuf = protobuf_common::ScalarValue::decode(bytes).map_err(|e| { |
| 82 | +//! plan_datafusion_err!("Error decoding ScalarValue as protobuf: {e}") |
| 83 | +//! })?; |
| 84 | +//! // Decode bytes from somewhere (over network, etc.) back to ScalarValue |
| 85 | +//! let decoded_val: ScalarValue = match protobuf.value { |
| 86 | +//! Some(protobuf_common::scalar_value::Value::Uint64Value(val)) => { |
| 87 | +//! ScalarValue::UInt64(Some(val)) |
| 88 | +//! } |
| 89 | +//! _ => unreachable!(), |
| 90 | +//! }; |
| 91 | +//! assert_eq!(val, decoded_val); |
87 | 92 | //! # Ok(()) |
88 | 93 | //! # } |
89 | 94 | //! ``` |
|
0 commit comments