public FieldContext FieldFromLean(TripField field)
        {
            var fc = new FieldContext(
                    field.Name,
                    (short)field.Identifier,
                //typeConverter.ConvertToString(field.Type),
                    MangleJavaMethodName(field.Name),
                    SetterName(field),
                    GetterName(field),
                    field.Required == Required.REQUIRED,
                    typeConverter.ConvertToGenType(field.Type)
                );

            return fc;

        }
Esempio n. 2
0
 private void BuildSerializeMapElement(StringBuilder sb, GenType genType, string iter, string map)
 {
     var kField = new FieldContext(iter, genType.KeyType);
     BuildSerializeField(sb, kField, "", true);
     var vField = new FieldContext(map + ".get(" + iter + ")", genType.ValueType);
     BuildSerializeField(sb, vField, "", true);
 }
Esempio n. 3
0
 private void BuildSerializeListElement(StringBuilder sb, GenType genType, string iter)
 {
     var eField = new FieldContext(iter, genType.ElementType);
     BuildSerializeField(sb, eField, "", true);
 }
Esempio n. 4
0
 private string FieldNameFromField(FieldContext field)
 {
     if (field.JavaName != null) return field.JavaName;
     return field.Name;
 }
Esempio n. 5
0
        private void BuildSerializeField(StringBuilder sb, FieldContext field, string prefix = "", bool isElement = false, bool isFieldLess = false)
        {
            var genType = field.GenType;
            var name = prefix + (isFieldLess ? "" : FieldNameFromField(field));
            if (genType.IsStruct)
            {
                BuildSerializeStruct(sb, name);
            }
            else if (genType.IsContainer)
            {
                BuildSerializeContainer(sb, name, genType);
            }
            else if (genType.IsBaseType || genType.IsEnum)
            {
                sb.Indent(level).Append("oprot.");

                if (genType.IsBaseType)
                {
                    switch (genType.GType)
                    {
                        case GType.Binary:
                            sb.Append("writeBinary(").Append(name).Append(");");
                            break;
                        case GType.String:
                            sb.Append("writeString(").Append(name).Append(");");
                            break;
                        case GType.Bool:
                            sb.Append("writeBool(").Append(name).Append(".booleanValue());");
                            break;
                        case GType.Byte:
                            sb.Append("writeByte(").Append(name).Append(".byteValue());");
                            break;
                        case GType.I16:
                            sb.Append("writeI16(").Append(name).Append(".shortValue());");
                            break;
                        case GType.I32:
                            sb.Append("writeI32(").Append(name).Append(".intValue());"); ;
                            break;
                        case GType.I64:
                            sb.Append("writeI64(").Append(name).Append(".longValue());");
                            break;
                        case GType.Double:
                            sb.Append("writeDouble(").Append(name).Append(".doubleValue());"); ;
                            break;
                        default:
                            throw new ArgumentException(string.Format("DO NOT KNOW HOW TO SERIALIZE BASE TYPE {0}", genType.GType));
                    }
                }
                else if (genType.IsEnum)
                {
                    sb.Append("writeI32(").Append(name).Append(".getValue());");
                }
                sb.AppendLine();
            }
            else
            {
                throw new ArgumentException(string.Format("DO NOT KNOW HOW TO SERIALIZE {0} TYPE {1}", field.Name, genType.JavaTypeName));
            }
        }
Esempio n. 6
0
 private string DeclareField(FieldContext field, bool init = false, string prefix = "")
 {
     string result = field.GenType.JavaTypeName + " " + prefix + field.Name;
     if (init)
     {
         result += " = null";
     }
     return result + ";";
 }
Esempio n. 7
0
        private void BuildDeserializeListElement(StringBuilder sb, GenType listType, string prefix = "")
        {
            string elem = Tmp("_elem");

            var felem = new FieldContext(elem, listType.ElementType);

            sb.Indent(level).Append(DeclareField(felem, true)).AppendLine();

            BuildDeserializeField(sb, felem);

            sb.Indent(level).Append(prefix).Append(".add(").Append(elem).Append(");").AppendLine();
        }
Esempio n. 8
0
        private void BuildDeserializeMapElement(StringBuilder sb, GenType mapType, string prefix = "")
        {
            string key = Tmp("_key");
            string val = Tmp("_val");

            var fkey = new FieldContext(key, mapType.KeyType);
            var fval = new FieldContext(val, mapType.ValueType);

            sb.Indent(level).Append(DeclareField(fkey)).AppendLine();
            sb.Indent(level).Append(DeclareField(fval)).AppendLine();

            BuildDeserializeField(sb, fkey);
            BuildDeserializeField(sb, fval);

            sb.Indent(level).Append(prefix).Append(".put(").Append(key).Append(", ").Append(val).Append(");").AppendLine();
        }
Esempio n. 9
0
 public void AddField(FieldContext field)
 {
     this.Fields.Add(field);
 }
Esempio n. 10
0
        private void BuildDeserializeField(StringBuilder sb, FieldContext field, string prefix = "", bool isFieldless = false)
        {
            var genType = field.GenType;

            string name = prefix + (isFieldless ? "" : FieldNameFromField(field));

            if (genType.IsStruct)
            {
                BuildDeserializeStruct(sb, genType.JavaTypeName, name);
            }
            else if (genType.IsContainer)
            {
                BuildDeserializeContainer(sb, genType, name);
            }
            else if (genType.IsBaseType || genType.IsEnum)
            {
                sb.Indent(level).Append(name).Append(" = ");

                if (genType.IsEnum)
                {
                    sb.Append(genType.JavaTypeName).Append(".findByValue(");
                }

                sb.Append("iprot.");

                if (genType.IsBaseType)
                {
                    switch (genType.GType)
                    {
                        case GType.Binary:
                            sb.Append("readBinary();");
                            break;
                        case GType.String:
                            sb.Append("readString();");
                            break;
                        case GType.Bool:
                            sb.Append("readBool();");
                            break;
                        case GType.Byte:
                            sb.Append("readByte();");
                            break;
                        case GType.I16:
                            sb.Append("readI16();");
                            break;
                        case GType.I32:
                            sb.Append("readI32();");
                            break;
                        case GType.I64:
                            sb.Append("readI64();");
                            break;
                        case GType.Double:
                            sb.Append("readDouble();");
                            break;
                        default:
                            throw new ArgumentException(string.Format("DO NOT KNOW HOW TO DESERIALIZE BASE TYPE {0}", genType.GType));
                    }
                }
                else if (genType.IsEnum)
                {
                    sb.Append("readI32());");
                }
                sb.AppendLine();
            }
            else
            {
                throw new ArgumentException(string.Format("DO NOT KNOW HOW TO DESERIALIZE FIELD {0} TYPE {1}", field.Name, genType.JavaTypeName));
            }
        }