ndef(nfc数据交换格式)解析器和验证器

ndef的Python项目详细描述


发布v0.1–2014年2月22日

ndef模块提供了根据nfc以ndef格式创建和解析消息和记录的方法。 论坛技术规范。其主要目的是提供原始ndef消息的全面验证。可能是 用于在将消息写入实际标记之前验证消息。

PyPI上可用。

用法

有效信息

>>> import ndef
>>> message_data = 'D1010F5402656E48656C6C6F20776F726C6421'.decode('hex')
>>> message = ndef.NdefMessage(message_data)
>>> record = message.records[0]
>>> record.tnf
1
>>> record.type
'T'
>>> record.id
>>> record.payload
'\x02enHello world!'
>>>

无效消息

>>> import ndef
>>> message_data = '9901050155610123456761'.decode('hex')
>>> message = ndef.NdefMessage(message_data)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "ndef\ndef.py", line 274, in __init__
    self.verify()
  File "ndef\ndef.py", line 278, in verify
    self._verify_begin_end()
  File "ndef\ndef.py", line 296, in _verify_begin_end
    raise InvalidNdefMessage("last record's ME flag is off")
ndef.ndef.InvalidNdefMessage: last record's ME flag is off
>>>

创建消息

>>> import ndef
>>> text_record = (ndef.TNF_WELL_KNOWN, ndef.RTD_TEXT, 'id', 'hello world')
>>> text_message = ndef.new_message(text_record)
>>> text_raw_ndef = text_message.to_buffer()
>>> text_raw_ndef.encode('hex')
'd9010b0254696468656c6c6f20776f726c64'
>>>

备选方案

许可证

Copyright (c) 2014 Amir Szekely

This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.

Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:

   1. The origin of this software must not be misrepresented; you must not
   claim that you wrote the original software. If you use this software
   in a product, an acknowledgment in the product documentation would be
   appreciated but is not required.

   2. Altered source versions must be plainly marked as such, and must not be
   misrepresented as being the original software.

   3. This notice may not be removed or altered from any source
   distribution.

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

推荐PyPI第三方库


热门话题
JavaEclipseMars没有保存首选项   java梯度同步失败:原因:启动失败:   java如何从嵌套的JSON获取数据?   java如何判断可观察对象中的任何对象满足一个条件?   java将字符串转换为保持相同值的byte[]数组   java有没有办法绕过AuditingEntityListener为测试设置数据?   从/usr/share/java中解析linux JAR依赖关系   安卓 My java函数抛出nullpointerexception?   java Gradle使用正确版本的依赖项   JBoss和Java6中带注释的WebService中的web服务ClassCastException   java如何修复codename one中的简单逻辑错误?   java如何迭代矩阵的索引?   java如何在JPanel不可见时将其保存为图像?   java HashMap如何在Kotlin中实现MutableMap接口?   javascript如何在单击后加载特定片段?   EclipseJava为纳什均衡获取所有玩家/策略组合   JavaSpring:Web服务REST在JSON上产生双反斜杠   java为什么ServletContext#getRealPath(“/”)返回相对路径?   java当我的游戏应该重新启动时,我应该如何处理重置SurfaceView和线程?