Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion construct/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3866,7 +3866,11 @@ def Optional(subcon):
>>> d.build(None)
b''
"""
return Select(subcon, Pass)
macro = Select(subcon, Pass)
def _emitfulltype(ksy, bitwise):
return dict(type=subcon._compileprimitivetype(ksy, bitwise), if_="not(_io.eof)")
macro._emitfulltype = _emitfulltype
return macro


def If(condfunc, subcon):
Expand Down Expand Up @@ -4465,6 +4469,11 @@ def _build(self, obj, stream, context, path):
def _sizeof(self, context, path):
return 0

def _emitprimitivetype(self, ksy, bitwise):
name = "instance_%s" % ksy.allocateId()
ksy.instances[name] = dict(**self.subcon._compilefulltype(ksy, bitwise))
return name

def _emitparse(self, code):
code.append("""
def parse_peek(io, func):
Expand Down