class Image(cst.TContainerBase):
     width: int = cst.TStructField(cs.Int8ub)
     height: int = cst.TStructField(cs.Int8ub)
     pixels: cst.Opt[bytes] = cst.TStructField(
         cs.Default(
             cs.Bytes(cs.this.width * cs.this.height),
             lambda ctx: bytes(ctx.width * ctx.height),
         ))
 class TestContainer(cst.TContainerBase):
     a: int = cst.TStructField(cs.Int16ub, "This is the documentation of a")
     b: int = cst.TStructField(
         cs.Int8ub,
         doc="This is the documentation of b\nwhich is multiline")
     c: int = cst.TStructField(
         cs.Int8ub,
         """
         This is the documentation of c
         which is also multiline
         """,
     )
 class TestContainer(cst.TContainerBase):
     a: int = cst.TStructField(cs.Int16ub)
     b: int = cst.TStructField(cs.Int8ub)
 class Image(cst.TContainerBase):
     signature: cst.Opt[bytes] = cst.TStructField(cs.Const(b"BMP"))
     width: int = cst.TStructField(cs.Int8ub)
     height: int = cst.TStructField(cs.Int8ub)
 class TestContainer(cst.TContainerBase):
     a: TestEnum = cst.TStructField(cst.TEnum(cs.Int8ub, TestEnum))
     b: int = cst.TStructField(cs.Int8ub)
 class TestContainer(cst.TContainerBase):
     _1: int = cst.TStructField(cs.Computed(7))
     _2: cst.Opt[bytes] = cst.TStructField(cs.Const(b"JPEG"))
     _3: None = cst.TStructField(cs.Pass)
     _4: None = cst.TStructField(cs.Terminated)
 class TestContainer(cst.TContainerBase):
     _1: cst.Opt[bytes] = cst.TStructField(cs.Const(b"\x00"))
     _2: None = cst.TStructField(cs.Padding(1))
     _3: None = cst.TStructField(cs.Pass)
     _4: None = cst.TStructField(cs.Terminated)
 class TestTContainer(cst.TContainerBase):
     a: cst.Opt[int] = cst.TStructField(cs.Const(1, cs.Byte))
     b: int = cst.TStructField(cs.Int8ub)
 class TestContainer(cst.TContainerBase):
     const_field: cst.Opt[bytes] = cst.TStructField(cs.Const(b"\x00"))
Exemple #10
0
 class InnerDataclass(cst.TContainerBase):
     b: int = cst.TStructField(cs.Byte)
Exemple #11
0
    class TestContainer(cst.TContainerBase):
        @dataclasses.dataclass
        class InnerDataclass(cst.TContainerBase):
            b: int = cst.TStructField(cs.Byte)

        a: InnerDataclass = cst.TStructField(cst.TStruct(InnerDataclass))