Commit Graph

25 Commits

Author SHA1 Message Date
Erik Arvidsson fd815b10ad Compute type based on value (#3338)
This moves the type off from the value and instead we compute it as we ask for.

This also changes how we detect cycles. If a named struct contains a struct with the
same name we now create a cycle between them. This also means that cycle types
now take a string and not a number.

For encoding we no longer write the type with the value (unless it is a types.Ref).

This is a format change so this takes us to 7.6

Fixes #3328
Fixes #3325
Fixes #3324
Fixes #3323
2017-04-06 17:43:49 -07:00
Eric Halpern 9ff2c1d855 Go slice to Noms Set mashalling (#3339)
* Go slice to Noms Set mashalling

fixes: #3335
2017-04-04 11:33:30 -07:00
Erik Arvidsson c964aff0af Remove types.Value Type() in favor of types.TypeOf() (#3337)
BREAKING CHANGE

This removes the `Type()` method from the `types.Value` interface.
Instead use the `types.TypeOf(v types.Value) bool` function.

Fixes #3324
2017-04-03 14:04:13 -07:00
Erik Arvidsson f1d7214af6 Update struct in memory representation (#3333)
* Update struct in memory representation

To contain struct name and field names.

This is in preparation for removing types from the value.

Towards ##3324

* Rename structFields to structTypeFields

* Undo change in vendoring

* searchField and copy
2017-04-02 07:46:39 -07:00
Ben Kalman 9a864dcfd4 Make marshal.MustFoo not go via defer-recover (#3305) 2017-03-29 15:18:46 -07:00
Erik Arvidsson d4b412fa1f Rename MakeStructType2 to MakeStructType (#3304)
and remove the old MakeStructType
2017-03-29 15:04:26 -07:00
Erik Arvidsson 22f70f585d Optional fields (#3287)
This adds optional fields to structs.

New version: 7.4

To create a struct type with optional fields use types.MakeStructType2

There are some API changes in this commit and there will be some more in followup commits.

Fixes #2327
2017-03-27 16:54:04 -07:00
Ben Kalman 6cffd88a4d Skip "original" field when marshaling type (#3285)
Instead of failing. Fixes https://github.com/attic-labs/noms/issues/3284
2017-03-20 19:27:54 -07:00
Erik Arvidsson 310742211c Marshal to type (#3221)
This takes a Go value and reads the Go type from that and returns a Noms
type for that.
2017-02-23 13:09:37 -08:00
Ben Kalman b0689cb2a4 Add the marshal.Marshaler interface (#3012)
This lets types provide their own Noms value marshaling.

Towards #2970.
2017-01-05 09:09:22 +11:00
Aaron Boodman fe53c15552 Marshal() should accept original field with empty value. (#2985) 2016-12-23 00:20:29 -08:00
Aaron Boodman e451a01441 Add support for original in marshal.Marshal (#2978)
Add support for `original` in marshal.Marshal

Now it roundtrips
2016-12-22 13:12:51 -08:00
Ben Kalman 4eca6085cb Allow skipping invalid fields when marshalling (#2967)
Currently unexported fields refuse to marshal or unmarshal, even if
they're told to skip. Now, they can be skipped. By default, they are
still errors.
2016-12-20 16:47:49 -08:00
Aaron Boodman 87958507b0 marshal.Unmarshal(): introduce omitempty and original support (#2900)
* marshal.Unmarshal(): introduce omitempty and original suppport.

Fixes #2795
Fixes #2796

* review comments
2016-12-02 15:13:00 -08:00
Eric Halpern ca232f0ad7 Support marshaling from and unmarshaling to *types.Type (#2892)
* Support marshaling from and unmarshaling to *types.Type

* Incorporate code review suggestions.
- Use fallthrough in switch
- Update decode godoc to spec *types.Type handling. Godoc for encode is fine as is.

toward: #2889
-
2016-12-02 11:32:35 -08:00
Eric Halpern 3f60749013 Fix race conditions in encoder to address photo-dedup segfault (#2852)
toward: #2849
2016-11-23 15:39:14 -08:00
Ben Kalman 96d10ac29f Improve Set marshaling to add encoding support, and decoding to map (#2845)
The only support that marshal has for Set at the moment is decoding to
slice.
2016-11-22 11:24:18 -08:00
Ben Kalman ff4ee3c3a9 Small refactor to marshal code to support upcoming "set" tag (#2843) 2016-11-18 17:44:10 -08:00
Aaron Boodman 8e64e636aa Introduce photo-dedup-by-date (#2826)
Introduce photo-dedup-by-date

This program deduplicates photos by the date they were taken. It considers two photos a group if they were separated by less than 5 seconds.
2016-11-15 14:07:57 -08:00
Erik Arvidsson 817af58a5b Add omitempty to Go marshal (#2784)
If you provide an omitempty tag and the Go value is the zero/empty value
then we do not include that field in the resulting Noms struct.

Towards #2376
2016-10-28 17:36:02 -07:00
Erik Arvidsson 99eb3306b6 Go Marshal: Title case struct names (#2408)
Make the name of the Noms struct start with a capital letter.

When unmarshalling a struct we now ignore the case.

This is a breaking change. If you previously marshalled a Go struct with a lower case name (ie "abc") the Noms struct we generate now has the name "Abc" (previously the name was "abc")

Towards #2376
2016-08-23 10:05:50 -07:00
Erik Arvidsson 0d6e9a56f7 Marshal and Unmarshal handling of interface{} (#2391)
When unmarshalling onto interface{}` the following rules are used:
 - `types.Bool` -> `bool`
 - `types.List` -> `[]T`, where `T` is determined recursively using the same rules.
 - `types.Map` -> `map[T]V`, where `T` and `V` is determined recursively using the same rules.
 - `types.Number` -> `float64`
 - `types.String` -> `string`
 - `types.Union` -> `interface`
 - Everything else an error

Towards #2376
2016-08-22 16:52:01 -07:00
Erik Arvidsson 78bb271d3f Go marshal maps (#2389)
Go maps are marshaled to Noms Map.

 Towards #2376
2016-08-18 17:54:16 -07:00
Erik Arvidsson 15d80f9afd Go marshal slices and arrays (#2381)
* Go marshal slices and arrays

Slices and arrays are marshaled to Noms List. For arrays we also enforce
that the length is the same.

Towards #2376
2016-08-17 14:46:50 -07:00
Erik Arvidsson c013f1ea1c Go marshal (#2374)
Basic support for creating Noms value from Go values as well as reading
Noms values onto Go values.

Typical usage:

```
// Go to Noms
type T struct {
  S string
  N int32
}
nomsVal, err := marshal.Marshal(T{"Hi", 42})

// Noms to Go
var goVal T
err = marshal.Unmarshal(types.NewStruct("T", types.StructData{
  "S": types.String("Bye"),
  "N": types.Number(555),
}, &goVal)
```

Fixes #1591
2016-08-16 11:47:32 -07:00