Documentation
¶
Index ¶
- Constants
- Variables
- func DecodeTextPayload(payload []byte) (string, error)
- func DecodeURIPayload(payload []byte) (string, error)
- func EncodeTextPayload(text, language string) ([]byte, error)
- func EncodeURIPayload(uri string) []byte
- func ParseURIRecord(payload []byte) (string, error)
- func URIPrefixCode(prefix string) byte
- func URIPrefixString(code byte) string
- type Message
- type Record
- func NewAbsoluteURIRecord(uri string, payload []byte) *Record
- func NewEmptyRecord() *Record
- func NewExternalRecord(externalType string, payload []byte) *Record
- func NewMediaRecord(mediaType string, payload []byte) *Record
- func NewTextRecord(text, language string) *Record
- func NewURIRecord(uri string) *Record
- type TextRecord
Constants ¶
const ( MIMETypeWiFi = "application/vnd.wfa.wsc" MIMETypeVCard = "text/vcard" MIMETypeJSON = "application/json" MIMETypeText = "text/plain" )
Common MIME types used in NFC.
const ( TNFEmpty byte = 0x00 // Empty record TNFWellKnown byte = 0x01 // NFC Forum well-known type TNFMedia byte = 0x02 // Media-type (RFC 2046) TNFAbsoluteURI byte = 0x03 // Absolute URI (RFC 3986) TNFExternal byte = 0x04 // NFC Forum external type TNFUnknown byte = 0x05 // Unknown TNFUnchanged byte = 0x06 // Unchanged (for chunked records) TNFReserved byte = 0x07 // Reserved )
TNF (Type Name Format) values as defined by NFC Forum.
const (
TextRecordType = "T"
)
Text record constants.
const URIRecordType = "U"
URI record constants.
Variables ¶
var ( ErrEmptyMessage = errors.New("ndef: empty message") ErrInvalidRecord = errors.New("ndef: invalid record") ErrTruncatedRecord = errors.New("ndef: truncated record data") ErrInvalidTNF = errors.New("ndef: invalid TNF value") ErrChunkedRecord = errors.New("ndef: chunked records not supported") )
Common errors.
var ( ErrTextPayloadTooShort = errors.New("ndef: text payload too short") ErrTextInvalidLangLen = errors.New("ndef: invalid language code length") ErrTextLanguageTooLong = errors.New("ndef: language code too long") ErrTextPayloadTruncated = errors.New("ndef: text payload truncated") )
Text record errors.
var ( ErrURIPayloadTooShort = errors.New("ndef: URI payload too short") ErrURIInvalidPrefixCode = errors.New("ndef: invalid URI prefix code") )
URI record errors.
Functions ¶
func DecodeTextPayload ¶
DecodeTextPayload is a convenience function that extracts just the text string.
func DecodeURIPayload ¶
DecodeURIPayload is an alias for ParseURIRecord for API consistency.
func EncodeTextPayload ¶
EncodeTextPayload creates a text record payload from text and language.
func EncodeURIPayload ¶
EncodeURIPayload creates a URI record payload with optimal prefix compression.
func ParseURIRecord ¶
ParseURIRecord extracts the full URI from a URI record payload.
func URIPrefixCode ¶
URIPrefixCode returns the prefix code for a given URI prefix string. Returns 0 if no match is found.
func URIPrefixString ¶
URIPrefixString returns the prefix string for a given code. Returns empty string for invalid codes.
Types ¶
type Message ¶
type Message struct {
Records []*Record
}
Message represents an NDEF message containing one or more records.
type Record ¶
type Record struct {
Type string
ID string
Payload []byte
TNF byte
// contains filtered or unexported fields
}
Record represents a single NDEF record.
func NewAbsoluteURIRecord ¶
NewAbsoluteURIRecord creates a new NDEF Absolute URI record. This is different from a URI well-known type record - the URI itself is the type.
func NewExternalRecord ¶
NewExternalRecord creates a new NDEF External Type record. External types use the format "domain:type" (e.g., "example.com:mytype").
func NewMediaRecord ¶
NewMediaRecord creates a new NDEF Media-type record. The mediaType parameter should be a MIME type (e.g., "text/plain", "application/json").
func NewTextRecord ¶
NewTextRecord creates a new NDEF Text record. The language parameter should be an IANA language code (e.g., "en", "en-US").
func NewURIRecord ¶
NewURIRecord creates a new NDEF URI record. The URI is automatically compressed using the NFC Forum URI prefix table if a matching prefix is found.
type TextRecord ¶
TextRecord represents parsed text record data.
func ParseTextRecord ¶
func ParseTextRecord(payload []byte) (*TextRecord, error)
ParseTextRecord extracts text content from a Text record payload.