Created
July 7, 2022 14:39
-
-
Save Akasurde/0207d2b9e6c5387938d08cc79bc4f49e to your computer and use it in GitHub Desktop.
Encode and decode ndef message
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') | |
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) | |
record = message.records[0] | |
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