我目前正在为libfreefare编写Go 包装器。libfreefare 的 API 包含以下函数:
struct mifare_desfire_file_settings {
uint8_t file_type;
uint8_t communication_settings;
uint16_t access_rights;
union {
struct {
uint32_t file_size;
} standard_file;
struct {
int32_t lower_limit;
int32_t upper_limit;
int32_t limited_credit_value;
uint8_t limited_credit_enabled;
} value_file;
struct {
uint32_t record_size;
uint32_t max_number_of_records;
uint32_t current_number_of_records;
} linear_record_file;
} settings;
};
int mifare_desfire_get_file_settings (MifareTag tag, uint8_t file_no, struct mifare_desfire_file_settings *settings);
包装这样一个功能的理想解决方案是什么?如果struct mifare_desfire_file_settings不包含任何联合,我的包装器可能看起来像这样:
type DESFireFileSettings struct {
// all fields exported, no methods
}
func (t DESFireTag) FileSettings(fileNo byte) (DESFireFileSettings, error)
我应该如何进行?
撒科打诨
相关分类