Created
July 7, 2022 14:53
-
-
Save Akasurde/17402f6e27e253b0c8376d63a70e5b5d to your computer and use it in GitHub Desktop.
Encode and decode multiple records
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ndef | |
import codecs | |
text_record = ( | |
(ndef.TNF_WELL_KNOWN, ndef.RTD_TEXT, b'id', b'hello world'), | |
(ndef.TNF_WELL_KNOWN, ndef.RTD_TEXT, b'id', b'hello world 2'), | |
(ndef.TNF_URI, ndef.RTD_URI, b'id', b'https://github.com'), | |
) | |
text_message = ndef.new_message(*text_record) | |
text_raw_ndef = text_message.to_buffer() | |
encoded_hello_world = codecs.encode(text_raw_ndef, 'hex_codec') | |
decoded_hello_world = codecs.decode(encoded_hello_world, 'hex_codec') | |
message = ndef.NdefMessage(decoded_hello_world) | |
for record in message.records: | |
print(record.tnf) | |
print(record.type) | |
print(record.id) | |
print(record.payload) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment