Commit Graph

11 Commits

Author SHA1 Message Date
Abhinav Gupta
98666305b5 Generalize gen-valuewrapper into atomicwrapper
valuewrapper can be used only to generate atomic wrapper types for
types which are stored as atomic.Value. This isn't necessary because the
same logic can be applied to atomic wrappers built on other types like
Duration and Bool.

Generalize valuewrapper into atomicwrapper with support for optional
pack/unpack functions which handle conversion to/from `interface{}`.
This lets Error hook in and install the `storedError` struct (now called
`packedError`) to avoid panics from nil storage or value type change.
2020-05-15 15:47:21 -07:00
Abhinav Gupta
5ed3279fd8 Mark generated files as such (#75)
Generated files should contain the following comment in the first few
lines for them to be considered generated by GitHub.

    Code generated by <executable>

The additional `@generated` tag does the same for Phabricator.
2020-05-12 13:49:16 -07:00
Abhinav Gupta
08f23f163e Generate atomic Value wrappers automatically
Rather than hand-writing wrappers around atomic.Value, generate them
automatically from the same template. The generator is at
internal/gen-valuewrapper. The generator correctly handles generating
wrapper structs for nillable types.
2020-05-12 11:30:18 -07:00
Abhinav Gupta
fb0c2ade64 string: Implement TextMarshaler, TextUnmarshaler (#70)
Since String holds textual information, instead of implementing
json.Marshaler and json.Unmarshaler, we should implement
encoding.TextMarshaler and encoding.TextUnmarshaler on String.

This makes it encodable and decodable using a variety of formats
including JSON, XML, YAML, and TOML.
2020-05-11 14:40:09 -07:00
Daniel Malmer
fcb7ed1e69 Add JSON Marshal and Unmarshal (#68)
Support serializing and deserializing atomic objects to/from JSON using
the JSON representation of the underlying types. Without this,
marshaling returns `{}`.

Per discussion in #68, `atomic.Value` does not yet implement support
because there's an open question as to whether it should implement it
even if the underlying type doesn't support JSON marshaling/
unmarshaling.

Resolves #49
2020-05-10 07:17:21 -07:00
Prashant Varanasi
e81582a97d Revert "Optimization for String.Store("")" (#32)
This optimization causes data races since we're changing the value field
without using atomics. E.g., a caller who has multiple goroutines
calling `Set("1")` and `Set("")` will race on the access to `s.v` since
one goroutine is trying to read it while the other sets it, neither
using atomic operations.

This reverts commit 16b44f14f0.
2017-11-14 08:16:11 -08:00
Bill Fumerola
16b44f14f0 Optimization for String.Store("") 2017-07-19 18:44:22 -04:00
Bill Fumerola
a85b15eff9 Use our own Value for String 2017-05-09 14:47:25 -07:00
Prashant Varanasi
e59e67d981 Use unexported field name instead of embedding
Unexported field name means the methods on different types look
more similar (e.g., &i.v instead of &i.int32 or &i.uint32).

For String, this is important since we don't want users to be
able to access the underlying atomic.Value
2016-07-18 12:50:08 -07:00
Prashant Varanasi
d938bba906 Fix NewString disregarding the passed in string 2016-07-18 11:07:34 -07:00
Prashant Varanasi
fecc23564a Add String as a type-safe wrapper for atomic.Value 2016-07-17 12:43:23 -07:00