writeEnumField writes an enum field respecting the field's RefMode. Java writes enum ordinals as unsigned VarUint32Small7, not signed zigzag. RefMode determines whether null flag is written, regardless of whether the local type is a pointer. This is important for compatible mode where remote TypeDef
(ctx *WriteContext, field *FieldInfo, fieldValue reflect.Value)
| 2711 | // RefMode determines whether null flag is written, regardless of whether the local type is a pointer. |
| 2712 | // This is important for compatible mode where remote TypeDef's nullable flag controls the wire format. |
| 2713 | func writeEnumField(ctx *WriteContext, field *FieldInfo, fieldValue reflect.Value) { |
| 2714 | buf := ctx.Buffer() |
| 2715 | isPointer := field.Kind == FieldKindPointer |
| 2716 | |
| 2717 | // Write null flag based on RefMode only (not based on whether local type is pointer) |
| 2718 | if field.RefMode != RefModeNone { |
| 2719 | if isPointer && fieldValue.IsNil() { |
| 2720 | buf.WriteInt8(NullFlag) |
| 2721 | return |
| 2722 | } |
| 2723 | buf.WriteInt8(NotNullValueFlag) |
| 2724 | } |
| 2725 | |
| 2726 | // Get the actual value to serialize |
| 2727 | targetValue := fieldValue |
| 2728 | if isPointer { |
| 2729 | if fieldValue.IsNil() { |
| 2730 | // RefModeNone but nil pointer - this is a protocol error in schema-consistent mode |
| 2731 | // Write zero value as fallback |
| 2732 | targetValue = reflect.Zero(field.Meta.Type.Elem()) |
| 2733 | } else { |
| 2734 | targetValue = fieldValue.Elem() |
| 2735 | } |
| 2736 | } |
| 2737 | // For pointer enum fields, the serializer is ptrToValueSerializer wrapping enumSerializer. |
| 2738 | // We need to call the inner enumSerializer directly with the dereferenced value. |
| 2739 | if ptrSer, ok := field.Serializer.(*ptrToValueSerializer); ok { |
| 2740 | ptrSer.valueSerializer.WriteData(ctx, targetValue) |
| 2741 | } else { |
| 2742 | field.Serializer.WriteData(ctx, targetValue) |
| 2743 | } |
| 2744 | } |
| 2745 | |
| 2746 | func setEnumValue(ctx *ReadContext, ptr unsafe.Pointer, kind reflect.Kind, ordinal uint32) bool { |
| 2747 | switch kind { |
no test coverage detected