types.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:pixelinkds 作者: hgrecco 项目源码 文件源码
def from_file(cls, fp, size=None):
        """Construct a Frame Descriptor object from binary data.

        Parameters
        ----------
        fp : file-like
             File-like object to read the Frame Descriptor from.
             The cursor must be at the position where the Frame Descriptor starts.

        size : int, optional
               the number of bytes to be read.
               If not given, the value inspected from the fp itself will be used.

        Returns
        -------
        FrameDescriptor

        .. note:: A number of bytes equal to `size` will be consumed from the fp.

        .. warning:
                  If the number of requested bytes is smaller than the size of the
                  Frame Descriptor, some fields might be left unfilled.


        """
        out = FrameDescriptor()

        if size is None:
            size = np.fromfile(fp, dtype=np.uint32, count=1)
            if size.size == 0:
                raise ValueError('Unexpected EOF')

            fp.seek(-size.nbytes, io.SEEK_CUR)

            size = size[0]

        if size > ct.sizeof(FrameDescriptor):
            raise ValueError('Number of requested bytes (%d) do not fit '
                             'in the data structure (%d)' % (size, ct.sizeof(out)))

        buf = fp.read(size)

        ct.memmove(ct.addressof(out), buf, size)

        return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号