Skip to content

Instantly share code, notes, and snippets.

@Akasurde
Created July 7, 2022 14:39
Show Gist options
  • Save Akasurde/0207d2b9e6c5387938d08cc79bc4f49e to your computer and use it in GitHub Desktop.
Save Akasurde/0207d2b9e6c5387938d08cc79bc4f49e to your computer and use it in GitHub Desktop.
Encode and decode ndef message
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