Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PrecomputeMarshalByReflection ¶
func PrecomputeMarshalByReflection( v reflect.Value, marshalOptions *protojson.MarshalOptions, ) (map[string]interface{}, error)
PrecomputeMarshalByReflection marshals a struct to a map[string]interface{} using reflection, handling nested proto.Message fields appropriately
Parameters:
- v: The reflect.Value of the struct to marshal
- marshalOptions: The protojson.MarshalOptions to use (optional)
Returns:
- map[string]interface{}: The marshaled struct as a map
- error: The error if any
Types ¶
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder is the implementation of the Encoder interface
func NewEncoder ¶
func NewEncoder() *Encoder
NewEncoder creates a new Encoder instance
Returns:
- *Encoder: the new Encoder instance
func (Encoder) Encode ¶
Encode encodes the given body to JSON
Parameters:
- body: The body to encode
Returns:
- ([]byte, error): The encoded body and the error if any
func (Encoder) EncodeAndWrite ¶
func (e Encoder) EncodeAndWrite( writer io.Writer, beforeWriteFn func() error, body interface{}, ) error
EncodeAndWrite encodes and writes the given body to the writer
Parameters:
- writer: The writer to write the encoded body to
- beforeWriteFn: The function to call before writing the body
- body: The body to encode
Returns:
- error: The error if any
func (Encoder) PrecomputeMarshal ¶
PrecomputeMarshal precomputes the marshaled body by reflecting on the instance
Parameters:
- body: The body to precompute the marshaled body for
Returns:
- (map[string]interface{}, error): The precomputed marshaled body and the error if any