2025-02-11 13:23:19 +05:30
|
|
|
# adapted from https://github.com/waku-org/nwaku/blob/master/waku/common/protobuf.nim
|
|
|
|
|
|
|
|
|
|
{.push raises: [].}
|
|
|
|
|
|
|
|
|
|
import libp2p/protobuf/minprotobuf
|
|
|
|
|
import libp2p/varint
|
2026-04-24 09:50:18 +02:00
|
|
|
import ./types/protobuf_error
|
2025-02-11 13:23:19 +05:30
|
|
|
|
2026-04-24 09:50:18 +02:00
|
|
|
export minprotobuf, varint, protobuf_error
|
2025-02-11 13:23:19 +05:30
|
|
|
|
|
|
|
|
converter toProtobufError*(err: minprotobuf.ProtoError): ProtobufError =
|
|
|
|
|
case err
|
|
|
|
|
of minprotobuf.ProtoError.RequiredFieldMissing:
|
2026-04-24 09:50:18 +02:00
|
|
|
return ProtobufError(kind: ProtobufErrorKind.MissingRequiredField, field: "unknown")
|
2025-02-11 13:23:19 +05:30
|
|
|
else:
|
2026-04-24 09:50:18 +02:00
|
|
|
return ProtobufError(kind: ProtobufErrorKind.DecodeFailure, error: err)
|
2025-02-11 13:23:19 +05:30
|
|
|
|
|
|
|
|
proc missingRequiredField*(T: type ProtobufError, field: string): T =
|
2026-04-24 09:50:18 +02:00
|
|
|
return ProtobufError.init(field)
|