(v reflect.Value, rdser *Serializer, f fieldInfo, cache *ctagsWCache)
| 820 | } |
| 821 | |
| 822 | func (enc *Encoder) encodeValue(v reflect.Value, rdser *Serializer, f fieldInfo, cache *ctagsWCache) error { |
| 823 | |
| 824 | if f.isNullable && v.IsNil() { |
| 825 | if !f.isOmitEmpty { |
| 826 | rdser.PutCTag(mkctag(TAG_NULL, f.ctagName, 0)) |
| 827 | } |
| 828 | return nil |
| 829 | } |
| 830 | |
| 831 | if f.isPtr { |
| 832 | v = v.Elem() |
| 833 | } |
| 834 | switch f.kind { |
| 835 | case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: |
| 836 | val := v.Int() |
| 837 | if val != 0 || !f.isOmitEmpty { |
| 838 | rdser.PutCTag(mkctag(TAG_VARINT, f.ctagName, 0)) |
| 839 | rdser.PutVarInt(val) |
| 840 | } |
| 841 | case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: |
| 842 | val := v.Uint() |
| 843 | if val != 0 || !f.isOmitEmpty { |
| 844 | rdser.PutCTag(mkctag(TAG_VARINT, f.ctagName, 0)) |
| 845 | rdser.PutVarInt(int64(val)) |
| 846 | } |
| 847 | case reflect.Float32: |
| 848 | val := v.Float() |
| 849 | if val != 0 || !f.isOmitEmpty { |
| 850 | // rdser.PutCTag(mkctag(TAG_FLOAT, f.ctagName, 0)) |
| 851 | // rdser.PutFloat32(float32(val)) |
| 852 | // FIXME: Encoding float64 for the some kind of compatibility. We should encode float32 here after full migration to v5 |
| 853 | rdser.PutCTag(mkctag(TAG_DOUBLE, f.ctagName, 0)) |
| 854 | rdser.PutDouble(val) |
| 855 | } |
| 856 | case reflect.Float64: |
| 857 | val := v.Float() |
| 858 | if val != 0 || !f.isOmitEmpty { |
| 859 | rdser.PutCTag(mkctag(TAG_DOUBLE, f.ctagName, 0)) |
| 860 | rdser.PutDouble(val) |
| 861 | } |
| 862 | case reflect.Bool: |
| 863 | vv := 0 |
| 864 | if v.Bool() { |
| 865 | vv = 1 |
| 866 | } |
| 867 | if vv != 0 || !f.isOmitEmpty { |
| 868 | rdser.PutCTag(mkctag(TAG_BOOL, f.ctagName, 0)) |
| 869 | rdser.PutVarUInt(uint64(vv)) |
| 870 | } |
| 871 | case reflect.String: |
| 872 | val := v.String() |
| 873 | if f.isUuid { |
| 874 | uuid, err := ParseUuid(val) |
| 875 | if err != nil { |
| 876 | return err |
| 877 | } |
| 878 | rdser.PutCTag(mkctag(TAG_UUID, f.ctagName, 0)) |
| 879 | rdser.PutUuid(uuid) |
no test coverage detected