Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tests/encode_decode/01_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ regions:
size: 35
used_size: 1
root:
cc_capacity: 312
ndef_tlv_payload_start: 8
ndef_tlv_payload_size: 303
data_size: 312
payload_size: 245
overhead: 67
Expand Down
3 changes: 3 additions & 0 deletions tests/encode_decode/02_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ regions:
size: 35
used_size: 1
root:
cc_capacity: 312
ndef_tlv_payload_start: 8
ndef_tlv_payload_size: 303
data_size: 312
payload_size: 245
overhead: 67
Expand Down
3 changes: 3 additions & 0 deletions tests/encode_decode/04_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ regions:
size: 35
used_size: 1
root:
cc_capacity: 312
ndef_tlv_payload_start: 8
ndef_tlv_payload_size: 303
data_size: 312
payload_size: 255
overhead: 57
Expand Down
3 changes: 3 additions & 0 deletions tests/encode_decode/05_info.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ regions:
size: 35
used_size: 1
root:
cc_capacity: 312
ndef_tlv_payload_start: 8
ndef_tlv_payload_size: 303
data_size: 312
payload_size: 269
overhead: 43
Expand Down
3 changes: 3 additions & 0 deletions tests/specific/unknown_info_1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ regions:
size: 35
used_size: 1
root:
cc_capacity: 312
ndef_tlv_payload_start: 8
ndef_tlv_payload_size: 303
data_size: 312
payload_size: 269
overhead: 43
Expand Down
3 changes: 3 additions & 0 deletions tests/specific/unknown_info_2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ regions:
size: 35
used_size: 1
root:
cc_capacity: 312
ndef_tlv_payload_start: 8
ndef_tlv_payload_size: 303
data_size: 312
payload_size: 269
overhead: 43
Expand Down
17 changes: 9 additions & 8 deletions utils/rec_info.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import argparse
import json
import sys
import yaml

from record import Record
from common import default_config_file
from opt_check import opt_check
from pathlib import Path
import referencing
import urllib.parse
from pathlib import Path

import jsonschema
import jsonschema.validators
import json
import referencing
import yaml
from common import default_config_file
from opt_check import opt_check
from record import Record

parser = argparse.ArgumentParser(prog="rec_info", description="Reads a record from the STDIN and prints various information about it in the YAML format")
parser.add_argument("-c", "--config-file", type=str, default=default_config_file, help="Record configuration YAML file")
Expand Down Expand Up @@ -64,6 +64,7 @@
if args.show_root_info:
overhead = len(record.data) - len(record.payload)
output["root"] = {
**record.root_info,
"data_size": len(record.data),
"payload_size": len(record.payload),
"overhead": overhead,
Expand Down
21 changes: 15 additions & 6 deletions utils/record.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import os
import ndef
import yaml
import cbor2
import io
import os
import types
import typing

from fields import Fields, EncodeConfig
import cbor2
import ndef
import yaml
from fields import EncodeConfig, Fields


class Region:
Expand Down Expand Up @@ -99,13 +99,17 @@ class Record:

regions: dict[str, Region] = None

# Debug information about the record - to be shown in the CLI if the user demands it
root_info: dict[str, typing.Any]

encode_config: EncodeConfig

def __init__(self, config_file: str, data: memoryview):
assert type(data) is memoryview

self.data = data
self.encode_config = EncodeConfig()
self.root_info = dict()

self.config_dir = os.path.dirname(config_file)
with open(config_file, "r", encoding="utf-8") as f:
Expand All @@ -124,6 +128,8 @@ def __init__(self, config_file: str, data: memoryview):
# TODO: Support 8-byte CC (with a different magic)
assert cc[0] == 0xE1, "Capability container magic number does not match"

self.root_info["cc_capacity"] = cc[2] * 8

# Find the NDEF TLV
while True:
base_tlv = data_io.read(2)
Expand All @@ -143,7 +149,10 @@ def __init__(self, config_file: str, data: memoryview):

# 0x03 = NDEF TLV
if tag == 0x03:
# Found it -
# Found it

self.root_info["ndef_tlv_payload_start"] = data_io.tell()
self.root_info["ndef_tlv_payload_size"] = tlv_len
break
else:
# Skip the TLV block
Expand Down