diff --git a/src/type_conversions.rs b/src/type_conversions.rs index be48501..7dfe417 100644 --- a/src/type_conversions.rs +++ b/src/type_conversions.rs @@ -1,5 +1,5 @@ use pyo3::prelude::*; -use pyo3::types::{IntoPyDict, PyAny, PyBool, PyByteArray, PyDict, PyFloat, PyList, PyLong, PyString}; +use pyo3::types::{IntoPyDict, PyAny, PyBool, PyByteArray, PyDict, PyFloat, PyList, PyLong, PyString, PyBytes}; use yrs::types::{Attrs, Change, EntryChange, Delta, Events, Path, PathSegment, Value}; use yrs::{Any, TransactionMut}; use std::ops::Deref; @@ -201,6 +201,9 @@ impl ToPython for Any { pub fn py_to_any(value: &PyAny) -> Any { if value.is_none() { Any::Null + } else if value.is_instance_of::() { + let v: &[u8] = value.extract().unwrap(); + Any::Buffer(v.into()) } else if value.is_instance_of::() { let v: &str = value.extract().unwrap(); Any::String(v.into()) diff --git a/tests/test_map.py b/tests/test_map.py index e7de559..bfe71d4 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -3,6 +3,11 @@ from pycrdt import Array, Doc, Map, Text +def test_binary_entry(): + doc = Doc({"m": Map({"bytes": b"012"})}) + assert doc["m"]["bytes"] == b"012" + + def test_str(): doc = Doc() map2 = Map({"key2": "val2"})