Ref values use the TargetRef to get the internal implementation
RegisterFromValFunction and ToNomsValueFromTypeRef were only used by
ref values at this point so these were renamed and simplified to be
more specific for ref values
This is needed to be able to round trip enums.
If there is no codegen for an enum that is read from the datastore we
now return a types.Enum which can be serialized back to the same
sequence.
The Ref of a TypeRef is used in a maps and then it is important that
we fix all empty refs to point at the current package.
Remove unneeded calls to fixupTypeRef and make sure we call it just
before using the TypeRef as a key in a map.
The generated code for typed structs now uses a Go struct which
implements Value directly. The fields in this struct uses the "user"
type. (The union value still uses types.Value though.)
When a typed struct is created by the decoder, it asks for a struct
builder which returns a channel that the values of the fields of the
struct are sent to.
We now do a recursive call which bottoms out with a ref.Ref for RefKind
Values. This means that we traverse into nested structures consistently.
The effect of this is that we get all the refs that the current chunk
references.
Before encoding a compoundBlob we create a compoundBlobStruct and
encode that instead.
After decoding we check if the value is a compoundBlobStruct and if so
we convert it to a compoundBlob.
Fixes#455, #165
When writing a Package we were writing the type refs describing the
types in Package. These are never referenced from anywhere and the
information is embedded into the Package chunk.
Packages usually gets registered using RegisterPackage which is called
by generated code. However, if the data in the data store was created
using another binary it is unlikely that the current binary registered
the same Package.
When writing values that depends on Packages we write the Package to
the ChunkStore...
When we read a value that depends on a Package and the Package has
not been registered we now read the Package out of the the ChunkStore
and register it for future uses.
When we write a value that has a TypeRef with a package we need to
write that package.
When we write a package that has dependencies we need to write the
dependent packages too.
Ref Values now have a TargetRef() method that returns the ref.Ref of
the target the Value is referencing.
Note: This is a breaking change. In old code the Ref() of the Value was
the Ref of the underlying target.
Fixes#464