chengxilo opened a new pull request, #2986:
URL: https://github.com/apache/iggy/pull/2986

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and 
enhancements. You can link an issue to this PR using the GitHub syntax. For 
example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   N/A
   
   ## Rationale
   
   Iggy, when read/write binary, use little endian. When there is a string, it 
has a prefix provide its length, and the actually string body. So instead of 
using the `binary.LittleEndian.Uint32(payload[processIDPos : processIDPos+4])` 
and use `position ++` , why not just wrap everything in a reader to make it 
simple and clear.
   
   As the Stats deserialize function need to be updated, I think this change 
would be helpful. 
https://github.com/apache/iggy/pull/2964#discussion_r2952160233
   
   Here is a example that shows the difference:
   Before:
   
https://github.com/apache/iggy/blob/9c8b5cc6ca682de6f3e7e0074224517e5488dc40/foreign/go/binary_serialization/stats_serializer.go#L53-L90
   
   
   
   After
   ```go
   func (s *Stats) UnmarshalBinary(payload []byte) error {
        r := newReader(payload)
        s.ProcessId = r.u32()
        s.CpuUsage = r.f32()
        s.TotalCpuUsage = r.f32()
        s.MemoryUsage = r.u64()
        s.TotalMemory = r.u64()
        s.AvailableMemory = r.u64()
        s.RunTime = r.u64()
        s.StartTime = r.u64()
        s.ReadBytes = r.u64()
        s.WrittenBytes = r.u64()
        s.MessagesSizeBytes = r.u64()
        s.StreamsCount = r.u32()
        s.TopicsCount = r.u32()
        s.PartitionsCount = r.u32()
        s.SegmentsCount = r.u32()
        s.MessagesCount = r.u64()
        s.ClientsCount = r.u32()
        s.ConsumerGroupsCount = r.u32()
        s.Hostname = r.u32LenStr()
        s.OsName = r.u32LenStr()
        s.OsVersion = r.u32LenStr()
        s.KernelVersion = r.u32LenStr()
        return r.Err()
   }
   ```
   <!--
   Why is this change needed? If the issue explains it well, a one-liner is 
fine.
   -->
   
   ## What changed?
   
   <!--
   2-4 sentences. Problem first (before), then solution (after).
   
   GOOD:
   
   "Messages were unavailable when background message_saver committed the
   journal and started async disk I/O before completion. Polling during
   this window found neither journal nor disk data.
   
   The fix freezes journal batches in the in-flight buffer before async 
persist."
   
   GOOD:
   
   "When many small messages accumulate in the journal, the flush passes
   thousands of IO vectors to writev(), exceeding IOV_MAX (1024 on Linux)."
   
   BAD:
   - Walls of text
   - "This PR adds..." (we can see the diff)
   -->
   
   A reader for byte slice is created.
   
   ## Local Execution
   
   - Passed 
   - Pre-commit hooks ran 
   
   <!--
   You must run your code locally before submitting.
   "Relying on CI" is not acceptable - PRs from authors who haven't run the 
code will be closed.
   
   Did you have `prek` installed? It runs automatically on commit and covers 
all project languages. See 
[CONTRIBUTING.md](https://github.com/apache/iggy/blob/master/CONTRIBUTING.md).
   -->
   
   ## AI Usage
   
   <!--
   If AI tools were used, please answer:
   1. Which tools? (e.g., GitHub Copilot, Claude, ChatGPT)
   2. Scope of usage? (e.g., autocomplete, generated functions, entire 
implementation)
   3. How did you verify the generated code works correctly?
   4. Can you explain every line of the code if asked?
   
   If no AI tools were used, write "None" or delete this section.
   -->
   1. smart Claude Sonnet 4.6 and my rotten brain
   2. entire implementation, manually modified some part to make sure the error 
output readablity.
   3. Reviewed the tests and code, actually modified some logic of reading 
binary and works well.
   4. yes


-- 
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