Skip to main content
Version: dev

Xlang Type Mapping

Note:

  • For type definition, see Type Systems in Spec
  • int16_t[n]/vector<T> indicates int16_t[n]/vector<int16_t>
  • The cross-language serialization is not stable, do not use it in your production environment.

User Type IDs

When registering user types (struct/ext/enum/union), the internal type ID is written as the 8-bit kind, and the user type ID is written separately as an unsigned varint32. There is no bit shift/packing, and user_type_id can be in the range 0~0xFFFFFFFE.

Examples:

User IDTypeInternal IDEncoded User IDDecimal
0STRUCT2700
0ENUM2500
1STRUCT2711
1COMPATIBLE_STRUCT2811
2NAMED_STRUCT2922

When reading type IDs:

  • Read internal type ID from the type ID field.
  • If the internal type is a user-registered kind, read user_type_id as varuint32.

Type Mapping

Fory TypeFory Type IDJavaPythonJavascriptC++GolangRust
bool1bool/BooleanboolBooleanboolboolbool
int82byte/Byteint/pyfory.int8Type.int8()int8_tint8i8
int163short/Shortint/pyfory.int16Type.int16()int16_tint16i16
int324int/Integerint/pyfory.fixed_int32Type.int32()int32_tint32i32
varint325int/Integerint/pyfory.int32Type.varint32()int32_tint32i32
int646long/Longint/pyfory.fixed_int64Type.int64()int64_tint64i64
varint647long/Longint/pyfory.int64Type.varint64()int64_tint64i64
tagged_int648long/Longint/pyfory.tagged_int64Type.tagged_int64()int64_tint64i64
uint89short/Shortint/pyfory.uint8Type.uint8()uint8_tuint8u8
uint1610int/Integerint/pyfory.uint16Type.uint16()uint16_tuint16u16
uint3211long/Longint/pyfory.fixed_uint32Type.uint32()uint32_tuint32u32
var_uint3212long/Longint/pyfory.uint32Type.varUInt32()uint32_tuint32u32
uint6413long/Longint/pyfory.fixed_uint64Type.uint64()uint64_tuint64u64
var_uint6414long/Longint/pyfory.uint64Type.varUInt64()uint64_tuint64u64
tagged_uint6415long/Longint/pyfory.tagged_uint64Type.taggedUInt64()uint64_tuint64u64
float816//////
float1617float/Floatfloat/pyfory.float16Type.float16()fory::float16_tfory.float16fory::f16
bfloat1618//////
float3219float/Floatfloat/pyfory.float32Type.float32()floatfloat32f32
float6420double/Doublefloat/pyfory.float64Type.float64()doublefloat64f64
string21StringstrStringstringstringString/str
list22List/Collectionlist/tuplearrayvectorsliceVec
set23Setset/setfory.SetSet
map24MapdictMapunordered_mapmapHashMap
enum25Enum subclassesenum subclasses/enum/enum
named_enum26Enum subclassesenum subclasses/enum/enum
struct27pojo/recorddata classobjectstruct/classstructstruct
compatible_struct28pojo/recorddata classobjectstruct/classstructstruct
named_struct29pojo/recorddata classobjectstruct/classstructstruct
named_compatible_struct30pojo/recorddata classobjectstruct/classstructstruct
ext31pojo/recorddata classobjectstruct/classstructstruct
named_ext32pojo/recorddata classobjectstruct/classstructstruct
union33Uniontyping.Union/std::variant<Ts...>/tagged union enum
none36nullNonenullstd::monostatenil()
duration37DurationtimedeltaNumberdurationDurationDuration
timestamp38InstantdatetimeNumberstd::chrono::nanosecondsTimeDateTime
date39DatedatetimeNumberfory::serialization::DateTimeDateTime
decimal40BigDecimalDecimalbigint///
binary41byte[]bytes/uint8_t[n]/vector<T>[n]uint8/[]TVec<uint8_t>
array42arraynp.ndarray//array/sliceVec
bool_array43bool[]ndarray(np.bool_)/bool[n][n]bool/[]TVec<bool>
int8_array44byte[]ndarray(int8)/int8_t[n]/vector<T>[n]int8/[]TVec<i8>
int16_array45short[]ndarray(int16)/int16_t[n]/vector<T>[n]int16/[]TVec<i16>
int32_array46int[]ndarray(int32)/int32_t[n]/vector<T>[n]int32/[]TVec<i32>
int64_array47long[]ndarray(int64)/int64_t[n]/vector<T>[n]int64/[]TVec<i64>
uint8_array48short[]ndarray(uint8)/uint8_t[n]/vector<T>[n]uint8/[]TVec<u8>
uint16_array49int[]ndarray(uint16)/uint16_t[n]/vector<T>[n]uint16/[]TVec<u16>
uint32_array50long[]ndarray(uint32)/uint32_t[n]/vector<T>[n]uint32/[]TVec<u32>
uint64_array51long[]ndarray(uint64)/uint64_t[n]/vector<T>[n]uint64/[]TVec<u64>
float8_array52//////
float16_array53float[]ndarray(float16)/fory::float16_t[n]/vector<T>[n]float16/[]TVec<fory::f16>
bfloat16_array54//////
float32_array55float[]ndarray(float32)/float[n]/vector<T>[n]float32/[]TVec<f32>
float64_array56double[]ndarray(float64)/double[n]/vector<T>[n]float64/[]TVec<f64>

Type info(not implemented currently)

Due to differences between type systems of languages, those types can't be mapped one-to-one between languages.

If the user notices that one type on a language corresponds to multiple types in Fory type systems, for example, long in java has type int64/varint64/h64, it means the language lacks some types, and the user must provide extra type info when using Fory.

Type annotation

If the type is a field of another class, users can provide meta hints for fields of a type, or for the whole type. Such information can be provided in other languages too:

  • java: use annotation.
  • cpp: use macro and template.
  • golang: use struct tag.
  • python: use typehint.
  • rust: use macro.

Here is en example:

  • Java:

    class Foo {
    @Int32Type(varint = true)
    int f1;
    List<@Int32Type(varint = true) Integer> f2;
    }
  • Python:

    class Foo:
    f1: pyfory.varint32
    f2: List[pyfory.varint32]