一种简单的循环缓冲区,用于处理字节流(例如从串行端口),主要基于enque。

bringbuf的Python项目详细描述


bringbuf是非常基本的循环缓冲实现。其目的是处理字节流(例如从串行端口)。它基于enque,这是一种在python中处理队列的有效方法。写入缓冲区的第一个字节,是从缓冲区读取的第一个字节。如果缓冲区已满,则溢出并覆盖最旧的数据。

代码可在github找到。

安装

要求

没有要求。bringbuf具有视图依赖项(collectionsitertoolswarnings),它们是核心模块。

设置

使用以下命令安装bringbuf

$ [sudo] pip install bringbuf

用法

#!/usr/bin/env python#coding=utf-8# The following example shows the basic usage of bRingBuf classfrombringbuf.bringbufimportbRingBuf# define a ring buffer with the size of 5 bytesbuf=bRingBuf(5)# the buffers length initially is zeroprint(buf.len)# check if buffer is empty (True)print(buf.is_empty())# enqueue 6 bytes to the buffer# (note that the buffer will overflow)buf.enqueue([0x01,0x02,0x03,0x04,0x05,0x06])# now five bytes are in the buffer (maximal number of bytes)print(buf.len)# check if buffer is empty (False)print(buf.is_empty())# read content of the whole buffer without removing any bytesprint(buf.read(buf.len))# read and remove three bytes from the bufferprint(buf.dequeue(3))# read content of the whole buffer without removing any bytesprint(buf.read(buf.len))# enque four new bytesbuf.enqueue([0x07,0x08,0x09])# read content of the whole buffer without removing any bytesprint(buf.read(buf.len))# check whether buffer contains a pattern?# this might be solved by buf.index, which also returns the index,# but this is a more descriptive way to checkprint(buf.contains([0x02,0x08]),buf.contains([0x07,0x08,0x09]))# index of patternsprint(buf.index([0x02,0x08]),buf.index([0x07,0x08,0x09]))# contains pattern (with offset)?print(buf.contains([0x02,0x08],2),buf.contains([0x07,0x08,0x09],offset=2))# index of patterns (with offset)print(buf.index([0x02,0x08],2),buf.index([0x07,0x08,0x09],2))# read with offsetprint(buf.read(3,3))# enqueue a single bytebuf.enqueue_byte(0xff)print(buf.read(buf.len))# dequeue a single byteprint(buf.dequeue_byte())

许可证

版权所有(c)2016 Andreas GSchossmann

兹免费准许任何人取得 本软件和相关文档文件(“软件”),用于处理 不受限制的软件,包括但不限于 使用、复制、修改、合并、发布、分发、再授权和/或销售副本 以及允许向其提供软件的人员 因此,必须满足以下条件:

上述版权公告及本许可公告须包括在 软件的拷贝或大部分。

本软件按“原样”提供,无任何形式的保证,明示或 默示的,包括但不限于适销性保证, 适合特定目的和不侵权。在任何情况下 作者或版权所有者应对任何索赔、损害或其他 责任,无论是在合同诉讼、侵权诉讼或其他诉讼中, 不属于或与本软件有关,或使用或与本软件的其他交易有关。 软件。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java将一个节点拖到另一个不运行JavaFX的节点中   java如何在spring boot中创建完全自定义的查询   java Arraylist和ArrayListBlockingQueue之间的区别是什么?   java Weblogic会中断长时间运行的线程吗   java如何调用displayAd()方法?   使用数组在两个组之间进行java IPL匹配   java如何在Eclipse中的org下创建测试套件。朱尼特   java获取屏幕上任意点的鼠标坐标   正则表达式需要java正则表达式方面的帮助   如何使用Java获取Ram大小和硬盘大小?   java如何将所需长度设置为数组中的整数?   安卓应用程序启动前的java程序已终止   swing设置要在Java代码中打印的页边距   迭代期间java故障安全迭代器的删除   java如何在main中调用方法,以便它们在同一行上输出?   编译Java:尝试播放mp3文件时出错   java如何使用Spring数据Rest在POST调用中保存嵌入对象   java JAXWS如何在端点外部注入SecurityContext