Example #1
0
// unmarshalFact decodes a fact from it's binary representation. The domain and
// transaction ID are passed in since they are not encoded with the fact itself.
// This is because facts are stored relative to a domain and a transaction.
func unmarshalFact(m *ProtoFact, b []byte, d string, t uint64, f *origins.Fact) error {
	m.Reset()

	if err := proto.Unmarshal(b, m); err != nil {
		return err
	}

	f.Domain = d
	f.Transaction = t

	f.Entity = &origins.Ident{
		Domain: m.GetEntityDomain(),
		Name:   m.GetEntity(),
	}

	f.Attribute = &origins.Ident{
		Domain: m.GetAttributeDomain(),
		Name:   m.GetAttribute(),
	}

	f.Value = &origins.Ident{
		Domain: m.GetValueDomain(),
		Name:   m.GetValue(),
	}

	f.Time = chrono.MicroTime(m.GetTime())

	if m.GetAdded() {
		f.Operation = origins.Assertion
	} else {
		f.Operation = origins.Retraction
	}

	return nil
}
Example #2
0
func unmarshalSegment(b []byte, s *Segment) error {
	m := ProtoSegment{}

	if err := proto.Unmarshal(b, &m); err != nil {
		return err
	}

	s.UUID = decodeUUID(m.GetUUID())
	s.Transaction = m.GetTransaction()
	s.Time = chrono.MicroTime(m.GetTime())
	s.Blocks = int(m.GetBlocks())
	s.Count = int(m.GetCount())
	s.Bytes = int(m.GetBytes())
	s.Next = decodeUUID(m.GetNext())
	s.Base = decodeUUID(m.GetBase())

	return nil
}