mirror of
https://github.com/logos-messaging/nim-sds.git
synced 2026-07-02 13:59:41 +00:00
refactor(protobuf): skip fixed-width fields via skipValue (no alloc)
Addresses review feedback: skipping a field by reading its value discards an allocated result. Use the codec's `skipValue`, which advances the stream without materialising the value. (The previous allocating length-delimited discard was already removed by the parse-once change; this applies the same intent to the fixed32/64 skips that remain.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
9d13804ec1
commit
f3c1b118df
@ -23,7 +23,7 @@ import results
|
||||
import faststreams/inputs
|
||||
from protobuf_serialization/codec import
|
||||
FieldHeader, WireKind, init, number, kind, toBytes, readHeader, readValue,
|
||||
puint64, pbytes, fixed64, fixed32
|
||||
skipValue, puint64, pbytes, fixed64, fixed32
|
||||
import ./types/protobuf_error
|
||||
|
||||
export results, protobuf_error
|
||||
@ -69,9 +69,9 @@ proc init*(T: type ProtoBuffer, data: seq[byte]): T =
|
||||
of WireKind.LengthDelim:
|
||||
pb.lengthDelims.mgetOrPut(hdr.number, @[]).add(seq[byte](readValue(stream, pbytes)))
|
||||
of WireKind.Fixed64:
|
||||
discard readValue(stream, fixed64)
|
||||
skipValue(stream, fixed64)
|
||||
of WireKind.Fixed32:
|
||||
discard readValue(stream, fixed32)
|
||||
skipValue(stream, fixed32)
|
||||
except CatchableError:
|
||||
pb.parseOk = false
|
||||
return pb
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user