martin-g commented on code in PR #445:
URL: https://github.com/apache/avro-rs/pull/445#discussion_r2732737171


##########
avro/tests/serde_human_readable_true.rs:
##########
@@ -127,7 +126,7 @@ fn avro_rs_440_uuid_fixed() -> TestResult {
     let mut buffer = Vec::new();
 
     assert!(apache_avro::util::set_serde_human_readable(true));
-    let mut writer = SpecificSingleObjectWriter::with_capacity(64)?;

Review Comment:
   nit: We can keep `with_capacity()` as a delegate to `new()` and deprecated 
for a version or two.



##########
avro/src/writer.rs:
##########
@@ -617,44 +630,54 @@ impl<T> SpecificSingleObjectWriter<T>
 where
     T: AvroSchema + Into<Value>,
 {
-    /// Write the `Into<Value>` to the provided Write object. Returns a result 
with the number
-    /// of bytes written including the header
-    pub fn write_value<W: Write>(&mut self, data: T, writer: &mut W) -> 
AvroResult<usize> {
-        let v: Value = data.into();
-        self.inner.write_value_ref(&v, writer)
+    /// Write the value to the writer
+    ///
+    /// Returns the number of bytes written.
+    ///
+    /// Each call writes a complete single-object encoded message (header + 
data),
+    /// making each message independently decodable.
+    pub fn write_value<W: Write>(&self, data: T, writer: &mut W) -> 
AvroResult<usize> {
+        writer
+            .write_all(&self.header)
+            .map_err(Details::WriteBytes)?;
+        let value: Value = data.into();
+        let bytes = write_value_ref_owned_resolved(&self.resolved, &value, 
writer)?;

Review Comment:
   If this fails then the writer will contain the already written header.
   How about something like:
   ```rust
   let mut buffer = Vec::new();
   let bytes = write_value_ref_owned_resolved(&self.resolved, &value, &mut 
buffer)?;
   writer.write_all(&self.header).map_err(Details::WriteBytes)?;
   writer.write_all(&buffer).map_err(Details::WriteBytes)?;
   Ok(bytes + self.header.len())
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to