mirror of
https://github.com/qmk/qmk_firmware.git
synced 2025-05-30 21:13:21 +00:00
Prep client gen for header parsing - templates
This commit is contained in:
parent
7bce3d7b25
commit
63c8e0c8a2
@ -2,35 +2,23 @@ from collections import namedtuple
|
|||||||
from enum import IntFlag, IntEnum
|
from enum import IntFlag, IntEnum
|
||||||
from struct import Struct
|
from struct import Struct
|
||||||
|
|
||||||
|
{% set type_definitions = [{'name':'XAPRequest', 'members': 'token length data', 'fmt':'<HB61s'}, {'name':'XAPResponse', 'members': 'token flags length data', 'fmt':'<HBB60s'}] %}
|
||||||
class XAPRequest(namedtuple('XAPRequest', 'token length data')):
|
{% for item in type_definitions -%}
|
||||||
fmt = Struct('<HB61s')
|
class {{ item.name }}(namedtuple('{{ item.name }}', '{{ item.members }}')):
|
||||||
|
fmt = Struct('{{ item.fmt }}')
|
||||||
|
|
||||||
def __new__(cls, *args):
|
def __new__(cls, *args):
|
||||||
return super().__new__(cls, *args)
|
return super().__new__(cls, *args)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def from_bytes(data):
|
def from_bytes(cls, data):
|
||||||
return XAPRequest._make(XAPRequest.fmt.unpack(data))
|
return cls._make(cls.fmt.unpack(data))
|
||||||
|
|
||||||
def to_bytes(self):
|
|
||||||
return self.fmt.pack(*list(self))
|
|
||||||
|
|
||||||
|
|
||||||
class XAPResponse(namedtuple('XAPResponse', 'token flags length data')):
|
|
||||||
fmt = Struct('<HBB60s')
|
|
||||||
|
|
||||||
def __new__(cls, *args):
|
|
||||||
return super().__new__(cls, *args)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def from_bytes(data):
|
|
||||||
return XAPResponse._make(XAPResponse.fmt.unpack(data))
|
|
||||||
|
|
||||||
def to_bytes(self):
|
def to_bytes(self):
|
||||||
return self.fmt.pack(*list(self))
|
return self.fmt.pack(*list(self))
|
||||||
|
|
||||||
|
|
||||||
|
{% endfor -%}
|
||||||
class XAPSecureStatus(IntEnum):
|
class XAPSecureStatus(IntEnum):
|
||||||
LOCKED = 0x00
|
LOCKED = 0x00
|
||||||
UNLOCKING = 0x01
|
UNLOCKING = 0x01
|
||||||
|
@ -37,9 +37,9 @@ class XAPRequest(namedtuple('XAPRequest', 'token length data')):
|
|||||||
def __new__(cls, *args):
|
def __new__(cls, *args):
|
||||||
return super().__new__(cls, *args)
|
return super().__new__(cls, *args)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def from_bytes(data):
|
def from_bytes(cls, data):
|
||||||
return XAPRequest._make(XAPRequest.fmt.unpack(data))
|
return cls._make(cls.fmt.unpack(data))
|
||||||
|
|
||||||
def to_bytes(self):
|
def to_bytes(self):
|
||||||
return self.fmt.pack(*list(self))
|
return self.fmt.pack(*list(self))
|
||||||
@ -51,9 +51,9 @@ class XAPResponse(namedtuple('XAPResponse', 'token flags length data')):
|
|||||||
def __new__(cls, *args):
|
def __new__(cls, *args):
|
||||||
return super().__new__(cls, *args)
|
return super().__new__(cls, *args)
|
||||||
|
|
||||||
@staticmethod
|
@classmethod
|
||||||
def from_bytes(data):
|
def from_bytes(cls, data):
|
||||||
return XAPResponse._make(XAPResponse.fmt.unpack(data))
|
return cls._make(cls.fmt.unpack(data))
|
||||||
|
|
||||||
def to_bytes(self):
|
def to_bytes(self):
|
||||||
return self.fmt.pack(*list(self))
|
return self.fmt.pack(*list(self))
|
||||||
|
Loading…
Reference in New Issue
Block a user