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:
Ivan FB 2026-06-10 17:18:41 +02:00
parent 9d13804ec1
commit f3c1b118df
No known key found for this signature in database
GPG Key ID: DF0C67A04C543270

View File

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