Skip to content

Commit

Permalink
Edit docstrings (#1302)
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison authored Nov 27, 2023
1 parent 7db0d87 commit f5a0127
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
8 changes: 4 additions & 4 deletions converter/composite_data_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ type (
}
)

// NewCompositeDataConverter creates new instance of CompositeDataConverter from ordered list of PayloadConverters.
// Order is important here because during serialization DataConverter will try PayloadsConverters in
// that order until PayloadConverter returns non nil payload.
// Last PayloadConverter should always serialize the value (JSONPayloadConverter is good candidate for it).
// NewCompositeDataConverter creates a new instance of CompositeDataConverter from an ordered list of PayloadConverters.
// Order is important here because during serialization the DataConverter will try the PayloadConverters in
// that order until a PayloadConverter returns non nil payload.
// The last PayloadConverter should always serialize the value (JSONPayloadConverter is a good candidate for it).
func NewCompositeDataConverter(payloadConverters ...PayloadConverter) DataConverter {
dc := &CompositeDataConverter{
payloadConverters: make(map[string]PayloadConverter, len(payloadConverters)),
Expand Down
8 changes: 4 additions & 4 deletions converter/json_payload_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import (
type JSONPayloadConverter struct {
}

// NewJSONPayloadConverter creates new instance of JSONPayloadConverter.
// NewJSONPayloadConverter creates a new instance of JSONPayloadConverter.
func NewJSONPayloadConverter() *JSONPayloadConverter {
return &JSONPayloadConverter{}
}

// ToPayload converts single value to payload.
// ToPayload converts a single value to a payload.
func (c *JSONPayloadConverter) ToPayload(value interface{}) (*commonpb.Payload, error) {
data, err := json.Marshal(value)
if err != nil {
Expand All @@ -49,7 +49,7 @@ func (c *JSONPayloadConverter) ToPayload(value interface{}) (*commonpb.Payload,
return newPayload(data, c), nil
}

// FromPayload converts single value from payload.
// FromPayload converts a single payload to a value.
func (c *JSONPayloadConverter) FromPayload(payload *commonpb.Payload, valuePtr interface{}) error {
err := json.Unmarshal(payload.GetData(), valuePtr)
if err != nil {
Expand All @@ -58,7 +58,7 @@ func (c *JSONPayloadConverter) FromPayload(payload *commonpb.Payload, valuePtr i
return nil
}

// ToString converts payload object into human readable string.
// ToString converts a payload object into a human-readable string.
func (c *JSONPayloadConverter) ToString(payload *commonpb.Payload) string {
return string(payload.GetData())
}
Expand Down
8 changes: 5 additions & 3 deletions converter/payload_converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ import (

// PayloadConverter is an interface to convert a single payload.
type PayloadConverter interface {
// ToPayload converts single value to payload. It should return nil if the PayloadConveter can not convert passed value (i.e. type is unknown).
// ToPayload converts a single value to payload. It should return nil if the
// PayloadConverter can not convert the passed value (i.e. type is unknown).
ToPayload(value interface{}) (*commonpb.Payload, error)
// FromPayload converts single value from payload. valuePtr should be a reference to the variable of the type that is corresponding for payload encoding.
// Otherwise it should return error.
// FromPayload converts single value from payload. valuePtr should be a
// reference to a variable of a type corresponding to the payload
// encoding. Otherwise it should return error.
FromPayload(payload *commonpb.Payload, valuePtr interface{}) error
// ToString converts payload object into human readable string.
ToString(*commonpb.Payload) string
Expand Down

0 comments on commit f5a0127

Please sign in to comment.