2022-11-16 19:02:14 +00:00
|
|
|
# Extensions for libp2p's protobuf library implementation
|
|
|
|
|
2022-11-04 09:52:27 +00:00
|
|
|
when (NimMajor, NimMinor) < (1, 4):
|
|
|
|
{.push raises: [Defect].}
|
|
|
|
else:
|
|
|
|
{.push raises: [].}
|
2022-06-16 14:04:47 +00:00
|
|
|
|
|
|
|
import
|
2022-11-17 19:40:08 +00:00
|
|
|
std/options,
|
2022-06-16 14:04:47 +00:00
|
|
|
libp2p/protobuf/minprotobuf,
|
|
|
|
libp2p/varint
|
2022-11-16 19:02:14 +00:00
|
|
|
|
|
|
|
export
|
|
|
|
minprotobuf,
|
|
|
|
varint
|
2022-06-16 14:04:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
proc write3*(proto: var ProtoBuffer, field: int, value: auto) =
|
2022-11-17 19:40:08 +00:00
|
|
|
when value is Option:
|
|
|
|
if value.isSome():
|
|
|
|
proto.write(field, value.get())
|
2022-11-18 17:37:08 +00:00
|
|
|
elif value is bool:
|
|
|
|
proto.write(field, zint(value))
|
2022-11-17 19:40:08 +00:00
|
|
|
else:
|
2022-06-16 14:04:47 +00:00
|
|
|
proto.write(field, value)
|
|
|
|
|
|
|
|
proc finish3*(proto: var ProtoBuffer) =
|
|
|
|
if proto.buffer.len > 0:
|
|
|
|
proto.finish()
|
|
|
|
else:
|
|
|
|
proto.offset = 0
|
|
|
|
|
|
|
|
proc `==`*(a: zint64, b: zint64): bool =
|
2022-09-13 10:37:06 +00:00
|
|
|
int64(a) == int64(b)
|