Skip to content

Instantly share code, notes, and snippets.

@Akasurde
Created July 7, 2022 14:53
Show Gist options
  • Save Akasurde/17402f6e27e253b0c8376d63a70e5b5d to your computer and use it in GitHub Desktop.
Save Akasurde/17402f6e27e253b0c8376d63a70e5b5d to your computer and use it in GitHub Desktop.
Encode and decode multiple records
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