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

add Unmarshal to convert TLVs to Go struct(s) #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

alovak
Copy link
Collaborator

@alovak alovak commented Jan 22, 2025

The bertlv.Unmarshal function allows you to unmarshal TLV data directly into Go structs using struct tags. Fields can be mapped to TLV tags using the bertlv struct tag:

type EMVData struct {
    DedicatedFileName   []byte `bertlv:"84"`
    ApplicationTemplate struct {
        ApplicationID                string `bertlv:"4F"`       // Will be converted to HEX string
        ApplicationLabel             string `bertlv:"50,ascii"` // Will be converted to ASCII string
        ApplicationPriorityIndicator []byte `bertlv:"87"`
    } `bertlv:"61"`
}

data := []bertlv.TLV{...} // Your TLV data
var emvData EMVData
err := bertlv.Unmarshal(data, &emvData)

// emvData.ApplicationTemplate.ApplicationID => "A0000000041010"
// emvData.ApplicationTemplate.ApplicationLabel => "Mastercard"
// emvData.ApplicationTemplate.ApplicationPriorityIndicator => []byte{0x.01}

README.md Show resolved Hide resolved
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

Successfully merging this pull request may close these issues.

2 participants