remove deprecated support for Option

This commit is contained in:
chirag-parmar 2024-10-28 12:45:20 +05:30
parent 72a88720c4
commit 276e3917d0
3 changed files with 20 additions and 43 deletions

View File

@ -7,30 +7,17 @@
{.push raises: [].} {.push raises: [].}
import std/typetraits, ./base, ../rlp import
std/typetraits, ./base, ../rlp,
../rlp/options as rlp_options
export base, rlp export base, rlp, rlp_options
# TODO why is rlp serialization of `Opt` here and not in rlp?
proc append*[T](w: var RlpWriter, val: Opt[T]) =
mixin append
if val.isSome:
w.append(val.get())
else:
w.append("")
template read*[T](rlp: var Rlp, val: var T) = template read*[T](rlp: var Rlp, val: var T) =
mixin read mixin read
val = rlp.read(type val) val = rlp.read(type val)
proc read*[T](rlp: var Rlp, val: var Opt[T]) {.raises: [RlpError].} =
mixin read
if rlp.blobLen != 0:
val = Opt.some(rlp.read(T))
else:
rlp.skipElem
proc read*(rlp: var Rlp, T: type StUint): T {.raises: [RlpError].} = proc read*(rlp: var Rlp, T: type StUint): T {.raises: [RlpError].} =
if rlp.isBlob: if rlp.isBlob:
let bytes = rlp.toBytes let bytes = rlp.toBytes

View File

@ -448,9 +448,6 @@ func readImpl(
else: else:
rlp.bytes.len() rlp.bytes.len()
template getUnderlyingType[T](_: Option[T]): untyped =
T
template getUnderlyingType[T](_: Opt[T]): untyped = template getUnderlyingType[T](_: Opt[T]): untyped =
T T
@ -458,16 +455,6 @@ func readImpl(
type FieldType {.used.} = type field type FieldType {.used.} = type field
when hasCustomPragmaFixed(RecordType, fieldName, rlpCustomSerialization): when hasCustomPragmaFixed(RecordType, fieldName, rlpCustomSerialization):
field = rlp.read(result, FieldType) field = rlp.read(result, FieldType)
elif field is Option:
# this works for optional fields at the end of an object/tuple
# if the optional field is followed by a mandatory field,
# custom serialization for a field or for the parent object
# will be better
type UT = getUnderlyingType(field)
if rlp.position < payloadEnd:
field = some(rlp.read(UT))
else:
field = none(UT)
elif field is Opt: elif field is Opt:
# this works for optional fields at the end of an object/tuple # this works for optional fields at the end of an object/tuple
# if the optional field is followed by a mandatory field, # if the optional field is followed by a mandatory field,

View File

@ -1,17 +1,20 @@
import import ../rlp
std/options, import results
../rlp
proc read*[T](rlp: var Rlp, O: type Option[T]): O {.inline.} = proc append*[T](w: var RlpWriter, val: Opt[T]) =
mixin read mixin append
if not rlp.isEmpty:
result = some read(rlp, T)
proc append*(writer: var RlpWriter, value: Option) = if val.isSome:
if value.isSome: w.append(val.get())
writer.append value.get
else: else:
writer.append "" w.append("")
export proc read*[T](rlp: var Rlp, val: var Opt[T]) {.raises: [RlpError].} =
options, rlp mixin read
if rlp.blobLen != 0:
val = Opt.some(rlp.read(T))
else:
rlp.skipElem
export
rlp, results