chronoxor / FastBinaryEncoding

Fast Binary Encoding is ultra fast and universal serialization solution for C++, C#, Go, Java, JavaScript, Kotlin, Python, Ruby, Swift
https://chronoxor.github.io/FastBinaryEncoding
MIT License
876 stars 90 forks source link

fbec should error-out on typo #50

Closed ghost closed 3 years ago

ghost commented 3 years ago

Typo in domain model, eg:

struct MyStruct {
    unt64 ShouldBoom;
}

Note unt64 instead of uint64. fbec happily produces:

// MyStruct struct
type MyStruct struct {
    ShouldBoom Unt64 `json:"ShouldBoom"`
}
chronoxor commented 3 years ago

GoLang generator treats 'unt64' as a struct name and generates filed with it using starting upper-case as go naming convention:

std::string GeneratorGo::ConvertTypeFieldName(const std::string& type)
{
    if (type == "bool")
        return "Bool";
    else if (type == "byte")
        return "Byte";
    else if (type == "bytes")
        return "Bytes";
    else if (type == "char")
        return "Char";
    else if (type == "wchar")
        return "WChar";
    else if (type == "int8")
        return "Int8";
    else if (type == "uint8")
        return "UInt8";
    else if (type == "int16")
        return "Int16";
    else if (type == "uint16")
        return "UInt16";
    else if (type == "int32")
        return "Int32";
    else if (type == "uint32")
        return "UInt32";
    else if (type == "int64")
        return "Int64";
    else if (type == "uint64")
        return "UInt64";
    else if (type == "float")
        return "Float";
    else if (type == "double")
        return "Double";
    else if (type == "decimal")
        return "Decimal";
    else if (type == "timestamp")
        return "Timestamp";
    else if (type == "string")
        return "String";
    else if (type == "uuid")
        return "UUID";

    std::string ns = "";
    std::string t = type;

    size_t pos = type.find_last_of('.');
    if (pos != std::string::npos)
    {
        ns.assign(type, 0, pos + 1);
        t.assign(type, pos + 1, type.size() - pos);
    }

    CppCommon::StringUtils::ReplaceAll(ns, ".", "");
    return ns + ConvertToUpper(t);
}
ghost commented 3 years ago

My expectation was that if the domain model file looked like this

package test

struct MyStruct {
    unt64 DoBoom;
}

the parser would report this as syntax error, since there is no custom type unt64 defined. And that the user should express the desire of using a custom type unt64 thus:

package test

struct unt64 {
    uint64 Blah;
}

struct MyStruct {
    unt64 NoBoom;
}
chronoxor commented 3 years ago

Yes, I agree! We'll fix it soon.

ghost commented 3 years ago

Awesome!