Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create message with multiple records #1

Closed
taglme opened this issue Nov 19, 2018 · 4 comments
Closed

Unable to create message with multiple records #1

taglme opened this issue Nov 19, 2018 · 4 comments

Comments

@taglme
Copy link

taglme commented Nov 19, 2018

It seems that ndef record header (first byte) not correctly encoded when there is several records in message. Order of records in message should be considered when Marshal records.
For example, I'm trying to create smart poster message
recordUri := ndef.NewURIRecord("http://example.com")
recordTitle := ndef.NewTextRecord("hello", "en")
payloadMessage:= &ndef.Message{[]*Record{recordUri, recordTitle}}
payloadByte, _ := payloadMessage.Marshal()
message := ndef.NewMessage(ndef.NFCForumWellKnownType, "Sp", "", payloadByte)

In this example payloadMessage not correctly Marshaled

@taglme taglme changed the title Unable to create smart poster record Unable to create message with multiple records Nov 19, 2018
@hsanjuan
Copy link
Owner

hsanjuan commented Nov 19, 2018

Hmm I don't have the smart poster spec around, but from the internet I see that:

. Smart Posters are a more complex type of NDEF record, where the payload is actually another NDEF message. The message embedded in the Smart Poster payload contains two NDEF records of its own, a URI and a text record. Since Smart Poster records have multiple records, they can deliver additional information about the URI, such as a title, icon, or suggested processing actions.

I think the problem is that my library does not know how to produce a payload for this type of well known format and defaults to a generic , because I could never access the spec. If you are so kind to explain or provide information on how it should look like I can try to add it. Otherwise, you need to make sure you adapt payloadByte to whatever the smart poster needs, as right now it's used without any modification when Marshaling the final message..

@taglme
Copy link
Author

taglme commented Nov 19, 2018

Ok, there is more generic example.
If I want to create message with two records
recordUrl1 := ndef.NewURIRecord("http://example1.com")
recordUrl2 := ndef.NewURIRecord("http://example2.com")
payloadMessage:= &Message{[]*Record{recordUrl1, recordUrl2}}
payloadByte, _ := payloadMessage.Marshal()

Here we will get two records that starts with the same byte 0xD1
This is because in records marshal MB and ME flags always set to true
tempChunk.MB = true
tempChunk.ME = true

By specs we should set MB byte for first record and ME byte for last record. When marshal record we should pay attention to their order in message in order to set first byte of record (ndef header flags) properly.
So in example first record should start from 0x91 byte and the second record from 0x51 byte

@taglme
Copy link
Author

taglme commented Nov 20, 2018

Hi! I make some fixes and create pull request. Could you check it?
It seems that message unmarshal need to be fixed too. As soon as there is an error occurred when try to unmarshal message with multiple record
Error is "Chunk Flag missing from some records"

@taglme
Copy link
Author

taglme commented Nov 20, 2018

By the way, why chunks flags should be set in all records but last (according to chunk check function)?
As I know this flag should be set only if we have chunked payload.
I think this check should omitted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants