diff --git a/betterproto-extras/src/merging.rs b/betterproto-extras/src/merging.rs index e7bb593..af8b26c 100644 --- a/betterproto-extras/src/merging.rs +++ b/betterproto-extras/src/merging.rs @@ -39,7 +39,7 @@ fn map_field_value(field_name: &str, field_value: Value, proto_meta: &PyAny) -> let py = proto_meta.py(); match field_value { Value::Bool(x) => Ok(x.to_object(py)), - Value::Bytes(x) => Ok(x.to_object(py)), + Value::Bytes(x) => Ok(PyBytes::new(py, &x).to_object(py)), Value::F32(x) => Ok(x.to_object(py)), Value::F64(x) => Ok(x.to_object(py)), Value::I32(x) => Ok(x.to_object(py)), diff --git a/example.py b/example.py index 75a97fd..86f1d9b 100644 --- a/example.py +++ b/example.py @@ -32,6 +32,7 @@ class Bar(betterproto.Message): enm: Enm = betterproto.enum_field(4) map: Dict[int, bool] = betterproto.map_field(5, betterproto.TYPE_INT64, betterproto.TYPE_BOOL) maybe: Optional[bool] = betterproto.message_field(6, wraps=betterproto.TYPE_BOOL) + bts: bytes = betterproto.bytes_field(7) # Serialization has not been changed yet. So nothing unusual here buffer = bytes( @@ -44,7 +45,8 @@ buffer = bytes( 1: True, 42: False }, - maybe=True + maybe=True, + bts=b'Hi There!' ) )