Skip to content

Latest commit

 

History

History
105 lines (79 loc) · 3.45 KB

todo.md

File metadata and controls

105 lines (79 loc) · 3.45 KB

Here is the plan organized as markdown:


Plan for Serializer Improvement

1. Separate Serializing of Different Kinds into Separate Functions

  • Action: Break down the serializeUnsupported function into specific handlers for different types:
    • serializePointer
    • serializeStruct
    • serializeSlice
    • serializeMap
    • serializeFunc
  • Goal: Make the code modular and maintainable by separating serialization logic for different kinds of data.

2. Print Function Name and Argument Names

  • Action: When serializing functions:
    • Extract function names, parameter names, and types using reflect.TypeOf and reflect.Func.
    • Modify the function descriptor to include parameter names in the format func(arg1 type1, arg2 type2).
  • Goal: Improve function serialization by displaying argument names for clarity.

3. Create a Serializer Interface and Struct

3.1 Serializer Interface

  • Action: Define a Serializer interface with a method Serialize(v interface{}).
  • Goal: Create a unified interface for all serializers.

3.2 SerializerRegistry Struct

  • Action: Define a SerializerRegistry struct that maintains maps of serializers for types and kinds:

    • typeSerializers: A map of type-specific serializers.
    • kindSerializers: A map of kind-specific serializers.
    • Priority should be given to type-specific serializers.

    Example:

    type Serializer interface {
        Serialize(v interface{}) (interface{}, error)
    }
    
    type SerializerRegistry struct {
        typeSerializers map[reflect.Type]Serializer
        kindSerializers map[reflect.Kind]Serializer
    }
  • Goal: Improve flexibility and abstraction by creating reusable serializers.


4. Context Map to Prevent Recursion

4.1 Context Map

  • Action: Introduce a context map map[uintptr]string to track serialized items:

    • The key is the uintptr (address) of the item.
    • The value is the dot-splitted path to the serialized field.

    Example:

    type SerializationContext struct {
        serializedItems map[uintptr]string
    }

4.2 Contain Method

  • Action: Implement the Contain method to check if an item has already been serialized.

    Example:

    func (c *SerializationContext) Contain(v interface{}, path string) bool {
        addr := reflect.ValueOf(v).Pointer()
        _, exists := c.serializedItems[addr]
        return exists
    }

4.3 Prevent Recursion

  • Action: Modify serialization logic to check the context map before processing each item, ensuring recursion is prevented.
  • Goal: Avoid infinite loops and recursion when serializing items that have already been processed.

Timeline & Priorities

Week 1

  • Break down serializeUnsupported into smaller, type-specific functions.
  • Implement the Serializer interface and SerializerRegistry struct.

Week 2

  • Enhance function serialization to include function names and argument names.
  • Implement the SerializationContext and Contain method.

Week 3

  • Integrate context checking to prevent recursion.
  • Write tests to verify the context handling and function serialization.

Week 4

  • Refactor and optimize the code.
  • Write documentation and finalize the implementation.

This plan will help streamline the serialization process, improve maintainability, and prevent issues with recursion. Let me know if you need any further adjustments!