Skip to content

Commit 43cf904

Browse files
committed
pre-finalise schema to save runtime
1 parent 8b7d9cb commit 43cf904

File tree

28 files changed

+404
-113
lines changed

28 files changed

+404
-113
lines changed

docs/source/pcapkit/protocols/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ Header Schema
4747
.. autoattribute:: __excluded__
4848
:no-value:
4949

50+
.. autodecorator:: pcapkit.protocols.schema.schema.schema_final
51+
5052
Data Model
5153
----------
5254

pcapkit/corekit/fields/collections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ def unpack(self, buffer: 'bytes | IO[bytes]', packet: 'dict[str, Any]') -> 'list
240240
241241
Important:
242242
If the option list ended before the specified size limit,
243-
set :attr:`self.option_padding <OptionField.option_padding>` as the remaining length to
244-
the ``packet`` argument such that the next fields can be
245-
aware of such informations.
243+
set :attr:`self.option_padding <OptionField.option_padding>`
244+
as the remaining length to the ``packet`` argument such that
245+
the next fields can be aware of such informations.
246246
247247
"""
248248
length = self._length

pcapkit/protocols/schema/application/ftp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from typing import TYPE_CHECKING
66

77
from pcapkit.corekit.fields.strings import BytesField
8-
from pcapkit.protocols.schema.schema import Schema
8+
from pcapkit.protocols.schema.schema import Schema, schema_final
99

1010
__all__ = ['FTP']
1111

1212

13+
@schema_final
1314
class FTP(Schema):
1415
"""Header schema for FTP packet."""
1516

pcapkit/protocols/schema/application/httpv1.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from typing import TYPE_CHECKING
66

77
from pcapkit.corekit.fields.strings import BytesField
8-
from pcapkit.protocols.schema.schema import Schema
8+
from pcapkit.protocols.schema.schema import Schema, schema_final
99

1010
__all__ = ['HTTP']
1111

1212

13+
@schema_final
1314
class HTTP(Schema):
1415
"""Header schema for HTTP/1.\* packet."""
1516

pcapkit/protocols/schema/application/httpv2.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pcapkit.corekit.fields.misc import ConditionalField, SchemaField, SwitchField
1313
from pcapkit.corekit.fields.numbers import EnumField, NumberField, UInt8Field, UInt32Field
1414
from pcapkit.corekit.fields.strings import BitField, BytesField, PaddingField
15-
from pcapkit.protocols.schema.schema import Schema
15+
from pcapkit.protocols.schema.schema import Schema, schema_final
1616
from pcapkit.utilities.logging import SPHINX_TYPE_CHECKING
1717

1818
__all__ = [
@@ -101,6 +101,7 @@ def http_frame_selector(pkt: 'dict[str, Any]') -> 'Field':
101101
return SchemaField(length=pkt['__length__'], schema=UnassignedFrame)
102102

103103

104+
@schema_final
104105
class HTTP(Schema):
105106
"""Header schema for HTTP/2 packet."""
106107

@@ -163,6 +164,7 @@ def post_process(self, packet: 'dict[str, Any]') -> 'Schema':
163164
return self
164165

165166

167+
@schema_final
166168
class UnassignedFrame(FrameType):
167169
"""Header schema for unassigned HTTP/2 frame payload."""
168170

@@ -173,6 +175,7 @@ class UnassignedFrame(FrameType):
173175
def __init__(self, data: 'bytes') -> 'None': ...
174176

175177

178+
@schema_final
176179
class DataFrame(FrameType):
177180
"""Header schema for HTTP/2 ``DATA`` frames."""
178181

@@ -199,6 +202,7 @@ class Flags(FrameType.Flags):
199202
def __init__(self, pad_len: 'Optional[int]', data: 'bytes') -> 'None': ...
200203

201204

205+
@schema_final
202206
class HeadersFrame(FrameType):
203207
"""Header schema for HTTP/2 ``HEADERS`` frames."""
204208

@@ -242,6 +246,7 @@ class Flags(FrameType.Flags):
242246
def __init__(self, pad_len: 'Optional[int]', stream_dep: 'Optional[StreamDependency]', weight: 'Optional[int]', fragment: 'bytes') -> 'None': ...
243247

244248

249+
@schema_final
245250
class PriorityFrame(FrameType):
246251
"""Header schema for HTTP/2 ``PRIORITY`` frames."""
247252

@@ -257,6 +262,7 @@ class PriorityFrame(FrameType):
257262
def __init__(self, stream: 'StreamDependency', weight: 'int') -> 'None': ...
258263

259264

265+
@schema_final
260266
class RSTStreamFrame(FrameType):
261267
"""Header schema for HTTP/2 ``RST_STREAM`` frames."""
262268

@@ -267,6 +273,7 @@ class RSTStreamFrame(FrameType):
267273
def __init__(self, error: 'Enum_ErrorCode') -> 'None': ...
268274

269275

276+
@schema_final
270277
class SettingPair(Schema):
271278
"""Header schema for HTTP/2 ``SETTINGS`` frame setting pairs."""
272279

@@ -279,6 +286,7 @@ class SettingPair(Schema):
279286
def __init__(self, id: 'Enum_Setting', value: 'int') -> 'None': ...
280287

281288

289+
@schema_final
282290
class SettingsFrame(FrameType):
283291
"""Header schema for HTTP/2 ``SETTINGS`` frames."""
284292

@@ -297,6 +305,7 @@ class Flags(FrameType.Flags):
297305
def __init__(self, settings: 'list[SettingPair] | bytes') -> 'None': ...
298306

299307

308+
@schema_final
300309
class PushPromiseFrame(FrameType):
301310
"""Header schema for HTTP/2 ``PUSH_PROMISE`` frames."""
302311

@@ -329,6 +338,7 @@ class Flags(FrameType.Flags):
329338
def __init__(self, pad_len: 'Optional[int]', stream: 'StreamID', fragment: 'bytes') -> 'None': ...
330339

331340

341+
@schema_final
332342
class PingFrame(FrameType):
333343
"""Header schema for HTTP/2 ``PING`` frames."""
334344

@@ -344,6 +354,7 @@ class Flags(FrameType.Flags):
344354
def __init__(self, data: 'bytes') -> 'None': ...
345355

346356

357+
@schema_final
347358
class GoawayFrame(FrameType):
348359
"""Header schema for HTTP/2 ``GOAWAY`` frames."""
349360

@@ -360,6 +371,7 @@ class GoawayFrame(FrameType):
360371
def __init__(self, stream: 'StreamID', error: 'Enum_ErrorCode', debug: 'bytes') -> 'None': ...
361372

362373

374+
@schema_final
363375
class WindowUpdateFrame(FrameType):
364376
"""Header schema for HTTP/2 ``WINDOW_UPDATE`` frames."""
365377

@@ -372,6 +384,7 @@ class WindowUpdateFrame(FrameType):
372384
def __init__(self, size: 'WindowSize') -> 'None': ...
373385

374386

387+
@schema_final
375388
class ContinuationFrame(FrameType):
376389
"""Header schema for HTTP/2 ``CONTINUATION`` frames."""
377390

pcapkit/protocols/schema/internet/ah.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
from pcapkit.corekit.fields.misc import PayloadField
99
from pcapkit.corekit.fields.numbers import EnumField, UInt8Field, UInt32Field
1010
from pcapkit.corekit.fields.strings import BytesField, PaddingField
11-
from pcapkit.protocols.schema.schema import Schema
11+
from pcapkit.protocols.schema.schema import Schema, schema_final
1212

1313
__all__ = ['AH']
1414

1515
if TYPE_CHECKING:
1616
from pcapkit.protocols.protocol import Protocol
1717

1818

19+
@schema_final
1920
class AH(Schema):
2021
"""Header schema for AH packet."""
2122

0 commit comments

Comments
 (0)