Beispiel #1
0
 def struct_pack(format, *args):
     return _struct_pack(format.encode('ascii'), *args)
Beispiel #2
0
 def struct_pack(format, *args):
     return _struct_pack(format.encode('ascii'), *args)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from struct import pack as _struct_pack

NULL_ = b"\xC0"
FALSE = b"\xC2"
TRUE = b"\xC3"

PACKED_UINT_8 = [_struct_pack(">B", value) for value in range(0x100)]
PACKED_UINT_16 = [_struct_pack(">H", value) for value in range(0x10000)]

UNPACKED_UINT_8 = {bytes(bytearray([x])): x for x in range(0x100)}
UNPACKED_UINT_16 = {_struct_pack(">H", x): x for x in range(0x10000)}

UNPACKED_MARKERS = {NULL_: None, TRUE: True, FALSE: False}
UNPACKED_MARKERS.update({bytes(bytearray([z])): z for z in range(0x00, 0x80)})
UNPACKED_MARKERS.update(
    {bytes(bytearray([z + 256])): z
     for z in range(-0x10, 0x00)})