148dfc69ee613a176f13b04c2310adb7a08fe6737rw# Copyright 2014 Google Inc. All rights reserved. 248dfc69ee613a176f13b04c2310adb7a08fe6737rw# 348dfc69ee613a176f13b04c2310adb7a08fe6737rw# Licensed under the Apache License, Version 2.0 (the "License"); 448dfc69ee613a176f13b04c2310adb7a08fe6737rw# you may not use this file except in compliance with the License. 548dfc69ee613a176f13b04c2310adb7a08fe6737rw# You may obtain a copy of the License at 648dfc69ee613a176f13b04c2310adb7a08fe6737rw# 748dfc69ee613a176f13b04c2310adb7a08fe6737rw# http://www.apache.org/licenses/LICENSE-2.0 848dfc69ee613a176f13b04c2310adb7a08fe6737rw# 948dfc69ee613a176f13b04c2310adb7a08fe6737rw# Unless required by applicable law or agreed to in writing, software 1048dfc69ee613a176f13b04c2310adb7a08fe6737rw# distributed under the License is distributed on an "AS IS" BASIS, 1148dfc69ee613a176f13b04c2310adb7a08fe6737rw# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1248dfc69ee613a176f13b04c2310adb7a08fe6737rw# See the License for the specific language governing permissions and 1348dfc69ee613a176f13b04c2310adb7a08fe6737rw# limitations under the License. 1448dfc69ee613a176f13b04c2310adb7a08fe6737rw 1548dfc69ee613a176f13b04c2310adb7a08fe6737rwfrom . import number_types as N 1648dfc69ee613a176f13b04c2310adb7a08fe6737rwfrom . import packer 1748dfc69ee613a176f13b04c2310adb7a08fe6737rwfrom .compat import memoryview_type 1848dfc69ee613a176f13b04c2310adb7a08fe6737rw 1948dfc69ee613a176f13b04c2310adb7a08fe6737rw 2048dfc69ee613a176f13b04c2310adb7a08fe6737rwdef Get(packer_type, buf, head): 2148dfc69ee613a176f13b04c2310adb7a08fe6737rw """ Get decodes a value at buf[head:] using `packer_type`. """ 2248dfc69ee613a176f13b04c2310adb7a08fe6737rw return packer_type.unpack_from(memoryview_type(buf), head)[0] 2348dfc69ee613a176f13b04c2310adb7a08fe6737rw 2448dfc69ee613a176f13b04c2310adb7a08fe6737rw 2548dfc69ee613a176f13b04c2310adb7a08fe6737rwdef Write(packer_type, buf, head, n): 2648dfc69ee613a176f13b04c2310adb7a08fe6737rw """ Write encodes `n` at buf[head:] using `packer_type`. """ 2748dfc69ee613a176f13b04c2310adb7a08fe6737rw packer_type.pack_into(buf, head, n) 28