-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d13f5fd
commit e306a6e
Showing
2 changed files
with
17 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,48 @@ | ||
#!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
import struct | ||
from typing import Callable | ||
from typing import NewType | ||
|
||
PackerType = NewType("PackerType", Callable[[int], bytes]) | ||
UnpackerType = NewType("UnpackerType", Callable[[bytes], int]) | ||
|
||
def makeBytePacker(byteorder="@"): | ||
|
||
def makeBytePacker(byteorder: str = "@") -> PackerType: | ||
"""""" | ||
return struct.Struct("{}B".format(byteorder)).pack | ||
|
||
|
||
def makeByteUnpacker(byteorder="@"): | ||
def makeByteUnpacker(byteorder: str = "@") -> UnpackerType: | ||
"""""" | ||
return struct.Struct("{}B".format(byteorder)).unpack | ||
|
||
|
||
def makeWordPacker(byteorder="@"): | ||
def makeWordPacker(byteorder: str = "@") -> PackerType: | ||
"""""" | ||
return struct.Struct("{}H".format(byteorder)).pack | ||
|
||
|
||
def makeWordUnpacker(byteorder="@"): | ||
def makeWordUnpacker(byteorder: str = "@") -> UnpackerType: | ||
"""""" | ||
return struct.Struct("{}H".format(byteorder)).unpack | ||
|
||
|
||
def makeDWordPacker(byteorder="@"): | ||
def makeDWordPacker(byteorder: str = "@") -> PackerType: | ||
"""""" | ||
return struct.Struct("{}I".format(byteorder)).pack | ||
|
||
|
||
def makeDWordUnpacker(byteorder="@"): | ||
def makeDWordUnpacker(byteorder: str = "@") -> UnpackerType: | ||
"""""" | ||
return struct.Struct("{}I".format(byteorder)).unpack | ||
|
||
|
||
def makeDLongPacker(byteorder="@"): | ||
def makeDLongPacker(byteorder: str = "@") -> PackerType: | ||
"""""" | ||
return struct.Struct("{}Q".format(byteorder)).pack | ||
|
||
|
||
def makeDLongUnpacker(byteorder="@"): | ||
def makeDLongUnpacker(byteorder: str = "@") -> UnpackerType: | ||
"""""" | ||
return struct.Struct("{}Q".format(byteorder)).unpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters