~cytrogen/vbhelper

ref: 84a1c1af72cae5cd4bb3ec95cc49fbbe8ce62c89 vbhelper/vb-nfc-reader/src/main/java/com/github/cfogrady/vbnfc/Utils.kt -rw-r--r-- 681 bytes
84a1c1af — Nacho Initial commit 1 year, 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package com.github.cfogrady.vbnfc

// ConverToPages converts the byte array into the paged structure used in NFC communication
// If data for the header isn't included, the first 8 pages will be 0 filled.
fun ConvertToPages(data: ByteArray, header: ByteArray? = null) : List<ByteArray> {
    val pages = ArrayList<ByteArray>()
    // setup blank header pages
    for (i in 0..7) {
        if (header != null) {
            val index = i*4
            pages.add(header.sliceArray(index..<index+4))
        } else {
            pages.add(byteArrayOf(0, 0, 0, 0))
        }
    }
    for(i in data.indices step 4) {
        pages.add(data.sliceArray(i..<i+4))
    }
    return pages
}