Skip to content

Commit

Permalink
[pdata] Clarify CopyTo and MoveTo behavior in godoc.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax committed Oct 13, 2022
1 parent f24a6ac commit dbf1651
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 92 deletions.
4 changes: 2 additions & 2 deletions pdata/internal/cmd/pdatagen/internal/base_slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (es ${structName}) At(ix int) ${elementName} {
return new${elementName}((*es.getOrig())[ix])
}
// CopyTo copies all elements from the current slice to the dest.
// CopyTo copies all elements from the current slice overriding the destination.
func (es ${structName}) CopyTo(dest ${structName}) {
srcLen := es.Len()
destCap := cap(*dest.getOrig())
Expand Down Expand Up @@ -340,7 +340,7 @@ func (es ${structName}) At(ix int) ${elementName} {
return new${elementName}(&(*es.getOrig())[ix])
}
// CopyTo copies all elements from the current slice to the dest.
// CopyTo copies all elements from the current slice overriding the destination.
func (es ${structName}) CopyTo(dest ${structName}) {
srcLen := es.Len()
destCap := cap(*dest.getOrig())
Expand Down
4 changes: 2 additions & 2 deletions pdata/internal/cmd/pdatagen/internal/base_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ func New${structName}() ${structName} {
return new${structName}(&${originName}{})
}
// MoveTo moves all properties from the current struct to dest
// MoveTo moves all properties from the current struct overriding the destination and
// resetting the current instance to its zero value
func (ms ${structName}) MoveTo(dest ${structName}) {
*dest.getOrig() = *ms.getOrig()
*ms.getOrig() = ${originName}{}
}`

const messageValueCopyToHeaderTemplate = `// CopyTo copies all properties from the current struct to the dest.
const messageValueCopyToHeaderTemplate = `// CopyTo copies all properties from the current struct overriding the destination.
func (ms ${structName}) CopyTo(dest ${structName}) {`

const messageValueCopyToFooterTemplate = `}`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func (ms ${structName}) Append(elms ...${itemType}) {
*ms.getOrig() = append(*ms.getOrig(), elms...)
}
// MoveTo moves ${structName} to another instance.
// MoveTo moves ${structName} overriding the destination and resetting the current instance to its zero value.
func (ms ${structName}) MoveTo(dest ${structName}) {
*dest.getOrig() = *ms.getOrig()
*ms.getOrig() = nil
}
// CopyTo copies ${structName} to another instance.
// CopyTo copies all elements from the current slice overriding the destination.
func (ms ${structName}) CopyTo(dest ${structName}) {
*dest.getOrig() = copy${structName}(*dest.getOrig(), *ms.getOrig())
}
Expand Down
4 changes: 2 additions & 2 deletions pdata/pcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (v Value) SetEmptySlice() Slice {
return newSlice(&av.ArrayValue.Values)
}

// CopyTo copies the attribute to a destination.
// CopyTo copies the Value instance overriding the destination.
func (v Value) CopyTo(dest Value) {
destOrig := dest.getOrig()
switch ov := v.getOrig().Value.(type) {
Expand Down Expand Up @@ -760,7 +760,7 @@ func (m Map) Range(f func(k string, v Value) bool) {
}
}

// CopyTo copies all elements from the current map to the dest.
// CopyTo copies all elements from the current map overriding the destination.
func (m Map) CopyTo(dest Map) {
newLen := len(*m.getOrig())
oldCap := cap(*dest.getOrig())
Expand Down
6 changes: 3 additions & 3 deletions pdata/pcommon/generated_common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions pdata/pcommon/generated_primitive_slice.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pdata/pcommon/generated_resource.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pdata/pcommon/trace_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,14 @@ func (ms TraceState) FromRaw(v string) {
*ms.getOrig() = v
}

// MoveTo moves TraceState to another instance.
// MoveTo moves the TraceState instance overriding the destination
// and resetting the current instance to its zero value.
func (ms TraceState) MoveTo(dest TraceState) {
*dest.getOrig() = *ms.getOrig()
*ms.getOrig() = ""
}

// CopyTo copies TraceState to another instance.
// CopyTo copies the TraceState instance overriding the destination.
func (ms TraceState) CopyTo(dest TraceState) {
*dest.getOrig() = *ms.getOrig()
}
18 changes: 9 additions & 9 deletions pdata/plog/generated_logs.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pdata/plog/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ func NewLogs() Logs {
return newLogs(&otlpcollectorlog.ExportLogsServiceRequest{})
}

// MoveTo moves all properties from the current struct to dest
// MoveTo moves the Logs instance overriding the destination and
// resetting the current instance to its zero value.
func (ms Logs) MoveTo(dest Logs) {
*dest.getOrig() = *ms.getOrig()
*ms.getOrig() = otlpcollectorlog.ExportLogsServiceRequest{}
}

// CopyTo copies all logs from ms to dest.
// CopyTo copies the Logs instance overriding the destination.
func (ms Logs) CopyTo(dest Logs) {
ms.ResourceLogs().CopyTo(dest.ResourceLogs())
}
Expand Down
Loading

0 comments on commit dbf1651

Please sign in to comment.