Example #1
0
func marshalFact(m *ProtoFact, f *origins.Fact) ([]byte, error) {
	m.Reset()

	m.EntityDomain = proto.String(f.Entity.Domain)
	m.Entity = proto.String(f.Entity.Name)

	m.AttributeDomain = proto.String(f.Attribute.Domain)
	m.Attribute = proto.String(f.Attribute.Name)

	m.ValueDomain = proto.String(f.Value.Domain)
	m.Value = proto.String(f.Value.Name)

	m.Time = proto.Int64(chrono.TimeMicro(f.Time))

	switch f.Operation {
	case origins.Assertion:
		m.Added = proto.Bool(true)
	case origins.Retraction:
		m.Added = proto.Bool(false)
	default:
		panic("fact: invalid op")
	}

	return proto.Marshal(m)
}
Example #2
0
func marshalSegment(s *Segment) ([]byte, error) {
	m := ProtoSegment{
		UUID:        encodeUUID(s.UUID),
		Transaction: proto.Uint64(s.Transaction),
		Time:        proto.Int64(chrono.TimeMicro(s.Time)),
		Blocks:      proto.Int32(int32(s.Blocks)),
		Count:       proto.Int32(int32(s.Count)),
		Bytes:       proto.Int32(int32(s.Bytes)),
		Next:        encodeUUID(s.Next),
		Base:        encodeUUID(s.Base),
	}

	return proto.Marshal(&m)
}