| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package rawdatastore | 5 package datastore |
| 6 | 6 |
| 7 import ( | 7 import ( |
| 8 "errors" | 8 "errors" |
| 9 "fmt" | 9 "fmt" |
| 10 "math" | 10 "math" |
| 11 "reflect" | 11 "reflect" |
| 12 "time" | 12 "time" |
| 13 | 13 |
| 14 "github.com/luci/gae/service/blobstore" | 14 "github.com/luci/gae/service/blobstore" |
| 15 ) | 15 ) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 // handle the error normally, use SetValue(..., NoIndex) instead. | 63 // handle the error normally, use SetValue(..., NoIndex) instead. |
| 64 func MkPropertyNI(val interface{}) Property { | 64 func MkPropertyNI(val interface{}) Property { |
| 65 ret := Property{} | 65 ret := Property{} |
| 66 if err := ret.SetValue(val, NoIndex); err != nil { | 66 if err := ret.SetValue(val, NoIndex); err != nil { |
| 67 panic(err) | 67 panic(err) |
| 68 } | 68 } |
| 69 return ret | 69 return ret |
| 70 } | 70 } |
| 71 | 71 |
| 72 // PropertyConverter may be implemented by the pointer-to a struct field which | 72 // PropertyConverter may be implemented by the pointer-to a struct field which |
| 73 // is serialized by RawDatastore. Its ToProperty will be called on save, and | 73 // is serialized by datastore. Its ToProperty will be called on save, and |
| 74 // it's FromProperty will be called on load (from datastore). The method may | 74 // it's FromProperty will be called on load (from datastore). The method may |
| 75 // do arbitrary computation, and if it encounters an error, may return it. This | 75 // do arbitrary computation, and if it encounters an error, may return it. This |
| 76 // error will be a fatal error (as defined by PropertyLoadSaver) for the | 76 // error will be a fatal error (as defined by PropertyLoadSaver) for the |
| 77 // struct conversion. | 77 // struct conversion. |
| 78 // | 78 // |
| 79 // Example: | 79 // Example: |
| 80 // type Complex complex | 80 // type Complex complex |
| 81 // func (c *Complex) ToProperty() (ret Property, err error) { | 81 // func (c *Complex) ToProperty() (ret Property, err error) { |
| 82 // // something like: | 82 // // something like: |
| 83 // err = ret.SetValue(fmt.Sprint(*c), true) | 83 // err = ret.SetValue(fmt.Sprint(*c), true) |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 } | 307 } |
| 308 p.propType = pt | 308 p.propType = pt |
| 309 p.value = value | 309 p.value = value |
| 310 p.indexSetting = is | 310 p.indexSetting = is |
| 311 if t == typeOfByteSlice { | 311 if t == typeOfByteSlice { |
| 312 p.indexSetting = NoIndex | 312 p.indexSetting = NoIndex |
| 313 } | 313 } |
| 314 return | 314 return |
| 315 } | 315 } |
| 316 | 316 |
| 317 // PropertyLoadSaver may be implemented by a user type, and RawDatastore will | 317 // PropertyLoadSaver may be implemented by a user type, and datastore will |
| 318 // use this interface to serialize the type instead of trying to automatically | 318 // use this interface to serialize the type instead of trying to automatically |
| 319 // create a serialization codec for it with helper.GetPLS. | 319 // create a serialization codec for it with helper.GetPLS. |
| 320 type PropertyLoadSaver interface { | 320 type PropertyLoadSaver interface { |
| 321 // Load takes the values from the given map and attempts to save them in
to | 321 // Load takes the values from the given map and attempts to save them in
to |
| 322 // the underlying object (usually a struct or a PropertyMap). If a fatal | 322 // the underlying object (usually a struct or a PropertyMap). If a fatal |
| 323 // error occurs, it's returned via error. If non-fatal conversion errors | 323 // error occurs, it's returned via error. If non-fatal conversion errors |
| 324 // occur, error will be a MultiError containing one or more ErrFieldMism
atch | 324 // occur, error will be a MultiError containing one or more ErrFieldMism
atch |
| 325 // objects. | 325 // objects. |
| 326 Load(PropertyMap) error | 326 Load(PropertyMap) error |
| 327 | 327 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 return err | 442 return err |
| 443 } | 443 } |
| 444 pm["$"+key] = []Property{prop} | 444 pm["$"+key] = []Property{prop} |
| 445 return nil | 445 return nil |
| 446 } | 446 } |
| 447 | 447 |
| 448 // Problem implements PropertyLoadSaver.Problem. It ALWAYS returns nil. | 448 // Problem implements PropertyLoadSaver.Problem. It ALWAYS returns nil. |
| 449 func (pm PropertyMap) Problem() error { | 449 func (pm PropertyMap) Problem() error { |
| 450 return nil | 450 return nil |
| 451 } | 451 } |
| OLD | NEW |