@@ -26,6 +26,58 @@ assert r == {'country': 'COUNTRY', 'isp': 'ISP'}
2626
2727## Examples
2828see [ csv_to_mmdb.py] ( ./examples/csv_to_mmdb.py )
29+ Here is a professional and clear translation of the README.md section from Chinese into English:
30+
31+ ## Using the Java Client
32+
33+ ### TLDR
34+
35+ When generating an MMDB file for use with the Java client, you must specify the ` int_type ` :
36+
37+ ``` python
38+ from mmdb_writer import MMDBWriter
39+
40+ writer = MMDBWriter(int_type = ' int32' )
41+ ```
42+
43+ Alternatively, you can explicitly specify data types using the [ Type Enforcement] ( #type-enforcement ) section.
44+
45+ ### Underlying Principles
46+
47+ In Java, when deserializing to a structure, the numeric types will use the original MMDB numeric types. The specific
48+ conversion relationships are as follows:
49+
50+ | mmdb type | java type |
51+ | --------------| ------------|
52+ | float (15) | Float |
53+ | double (3) | Double |
54+ | int32 (8) | Integer |
55+ | uint16 (5) | Integer |
56+ | uint32 (6) | Long |
57+ | uint64 (9) | BigInteger |
58+ | uint128 (10) | BigInteger |
59+
60+ When using the Python writer to generate an MMDB file, by default, it converts integers to the corresponding MMDB type
61+ based on the size of the ` int ` . For instance, ` int(1) ` would convert to ` uint16 ` , and ` int(2**16+1) ` would convert
62+ to ` uint32 ` . This may cause deserialization failures in Java clients. Therefore, it is necessary to specify
63+ the ` int_type ` parameter when generating MMDB files to define the numeric type accurately.
64+
65+ ## Type Enforcement
66+
67+ MMDB supports a variety of numeric types such as ` int32 ` , ` uint16 ` , ` uint32 ` , ` uint64 ` , ` uint128 ` for integers,
68+ and ` f32 ` , ` f64 ` for floating points, while Python only has one integer type and one float type (actually ` f64 ` ).
69+
70+ Therefore, when generating an MMDB file, you need to specify the ` int_type ` parameter to define the numeric type of the
71+ MMDB file. The behaviors for different ` int_type ` settings are:
72+
73+ | int_type | Behavior |
74+ | ----------------| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
75+ | auto (default) | Automatically selects the MMDB numeric type based on the value size. <br />Rules: <br />` int32 ` for value < 0 <br />` uint16 ` for 0 <= value < 2^16<br />` uint32 ` for 2^16 <= value < 2^32<br />` uint64 ` for 2^32 <= value < 2^64<br /> ` uint128 ` for value >= 2^64. |
76+ | i32 | Stores all integer types as ` int32 ` . |
77+ | u16 | Stores all integer types as ` uint16 ` . |
78+ | u32 | Stores all integer types as ` uint32 ` . |
79+ | u64 | Stores all integer types as ` uint64 ` . |
80+ | u128 | Stores all integer types as ` uint128 ` . |
2981
3082
3183## Reference:
0 commit comments