Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decode into pointer fields in-place. #38

Open
ianremmler opened this issue Sep 25, 2015 · 0 comments
Open

Decode into pointer fields in-place. #38

ianremmler opened this issue Sep 25, 2015 · 0 comments
Labels
v1 Relates to the v1 line of releases

Comments

@ianremmler
Copy link

It would be nice if decodePtr() would operate on the thing being pointed to rather than decoding into a new concrete value and assigning its address to the pointer.

I've found this behaviour handy using encoding/json, for example. Say I have a struct prepopulated with defaults. The struct corresponds to options nested under a key in a config file. I can create an instance of an anonymous struct with a field whose name refers to that key and value is a pointer to my original struct. I can then decode into the anonymous struct instance, and only fields present in the config file data will be updated, leaving the default fields intact.

ianremmler added a commit to ianremmler/hcl that referenced this issue Sep 25, 2015
If decoding into a pointer, and the pointer points to a value, decode
into the exitsing value.  Otherwise, decode into a new value and point
to it.

Addresses issue hashicorp#38.
ianremmler added a commit to ianremmler/hcl that referenced this issue Sep 25, 2015
If decoding into a pointer, and the pointer points to a value, decode
into the exitsing value.  Otherwise, decode into a new value and point
to it.

Addresses issue hashicorp#38.
@apparentlymart apparentlymart added the v1 Relates to the v1 line of releases label Aug 27, 2018
langmartin pushed a commit that referenced this issue Apr 25, 2019
If decoding into a pointer, and the pointer points to a value, decode
into the exitsing value.  Otherwise, decode into a new value and point
to it.

Addresses issue #38.
langmartin added a commit that referenced this issue Apr 25, 2019
Slight adaptation of Ian Remmler <ian@remmler.org>'s fix in pr #39:

> If decoding into a pointer, and the pointer points to a value, decode
> into the exitsing value.  Otherwise, decode into a new value and point
> to it.
> Addresses issue #38.
langmartin added a commit that referenced this issue Apr 25, 2019
Slight adaptation of Ian Remmler <ian@remmler.org>'s fix in pr #39:

> If decoding into a pointer, and the pointer points to a value, decode
> into the exitsing value.  Otherwise, decode into a new value and point
> to it.
> Addresses issue #38.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v1 Relates to the v1 line of releases
Projects
None yet
Development

No branches or pull requests

2 participants