cloudflare / py-mmdb-encoder

Create mmdb files to encode prefix lists.
BSD 3-Clause "New" or "Revised" License
30 stars 11 forks source link

Implement boolean field #3

Open lspgn opened 6 years ago

swontroba commented 5 years ago

I have also a question related to boolean fields. I tried to generate the file / information here:

https://github.com/maxmind/MaxMind-DB/blob/master/source-data/GeoIP2-Precision-Enterprise-Test.json

And extended def python_data_to_mmdb_struct(data): with

elif type(data) is bool:
            newstruct['type'] = 'boolean'
            newstruct['content'] = 1 if data else 0

In the process to generate the data I get problems with the list and _write_v function.

Any Idea how to fix it seems like with the list and dict in there I would need anouther loop. So far I could not find out where.

lspgn commented 5 years ago

@swontroba will take a look. Could you give me more information about the problems with the list?

swontroba commented 5 years ago

In subdivisions part of the link out of my fist post you have in the list a dict with information. Based on the spec it is possible to have several. On the other hand it was just a test to see if I could recreate the structure of some of the MM test data.

"subdivisions" : [
{}]

If I just extend the python_data_to_mmdb_struct function with "bool" like I did. The write out process will process down till the _write_v function of the Encoder class and you get a type error

TypeError: a bytes-like object is required, not 'list' I guess you would have to detect if it is a list before and enter. I could not figure it out.

If I use a simple row structure everything works fine in my test example but I will to some tests regarding size. If I have several networks for the same data. It seems like the data should be reuse. I will have to look into this and check the size of the mmdb.