© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•7mo ago•
14 replies
Benny

Utf8JsonReader How to partial skip across buffers

Hi, I've been meaning to write a high performance low alloc way of reading an OpenAI chat/completions request body to scan for the
model
model
property. In many cases it appears at the start of a request body, before any prompts. So there is no point in reading the entire json document as prompts can have up to 1 million chars.

I came up with this: https://gist.github.com/bbartels/b37008a1bb6b2e0f6b462920b2c85140

And while it works, it only does if the document fits into the buffer. I waote a test where a property had a significant amount of data, and
.Skip
.Skip
would throw.

I've attempted to use
TrySkip
TrySkip
, but when that fails it resets the state of the reader back to before the skip. Is there a way to attempt a skip, but keep the reader state. Such that you can continue on the next chunk of the buffer?
Gist
OpenAIRequestInspector.cs
GitHub Gist: instantly share code, notes, and snippets.
OpenAIRequestInspector.cs
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Utf8JsonReader.GetString exceptions
C#CC# / help
3y ago
How to skip exception
C#CC# / help
2y ago
✅ Extracting an object from a Utf8JsonReader
C#CC# / help
4y ago
✅ [[QUESTION]] HOW TO CALCULATE THE Rent(int) property for System.Buffers.ArrayPool<byte> ?
C#CC# / help
4y ago