| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2017 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package model |
| 6 |
| 7 import ( |
| 8 "bytes" |
| 9 |
| 10 ds "github.com/luci/gae/service/datastore" |
| 11 "github.com/luci/luci-go/common/data/cmpbin" |
| 12 ) |
| 13 |
| 14 // ManifestLink is an in-MILO link to a named source manifest. |
| 15 type ManifestLink struct { |
| 16 // The name of the manifest as the build annotated it. |
| 17 Name string |
| 18 |
| 19 // The manifest ID (sha256). |
| 20 ID []byte |
| 21 } |
| 22 |
| 23 var _ ds.PropertyConverter = (*ManifestLink)(nil) |
| 24 |
| 25 // FromProperty implements ds.PropertyConverter |
| 26 func (m *ManifestLink) FromProperty(p ds.Property) (err error) { |
| 27 val, err := p.Project(ds.PTBytes) |
| 28 if err != nil { |
| 29 return err |
| 30 } |
| 31 buf := bytes.NewReader(val.([]byte)) |
| 32 if m.Name, _, err = cmpbin.ReadString(buf); err != nil { |
| 33 return |
| 34 } |
| 35 m.ID, _, err = cmpbin.ReadBytes(buf) |
| 36 return |
| 37 } |
| 38 |
| 39 // ToProperty implements ds.PropertyConverter |
| 40 func (m *ManifestLink) ToProperty() (ds.Property, error) { |
| 41 buf := bytes.NewBuffer(nil) |
| 42 cmpbin.WriteString(buf, m.Name) |
| 43 cmpbin.WriteBytes(buf, m.ID) |
| 44 return ds.MkProperty(buf.Bytes()), nil |
| 45 } |
| OLD | NEW |