一种简单的循环缓冲区,用于处理字节流(例如从串行端口),主要基于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 Spring freemarker多模板加载程序路径   在java插件中从控制台获取输入   java在包中创建继承类   网页抓取Java Jsoup网页抓取   java在线程内创建一个对象,而true条件具有相同的引用   java如何根据空格数拆分字符串   java新的安卓 studio更新中的配置文件“app”是什么?   java在将ArrayList写入/读取到文件时出现奇怪的问题   java Reg替换文本块第一次出现+最后一次出现   java当我单击任何RecyclerView列表项时,如何在MainActivity的EditText中显示特定的单击项?   JAVA XML删除节点仅删除第一个外观   java如何在数组中查找特定值   java SVG/矢量图形对象布尔运算(并集、交集、减法)   java在Android中创建线程需要多长时间   尝试从JBOSS联系Oracle LDAP服务器时发生java连接重置异常   java基于参数获取特定的实现实例   使用java就地修改文件内容   java MonetaryException:未加载MonetaryAmountsSingletonSpi   java接受用户的不同输入并使其触发完全相同的代码段的最短方法是什么   Spring 3.2.8应用程序中未找到java HTTP 404错误