refactor frame options to reduce code duplication

This commit is contained in:
Travis 2017-06-28 13:45:07 -05:00
parent 4d2b009315
commit f68110be8b
No known key found for this signature in database
GPG key ID: 7F08008DFD9314C9

View file

@ -213,6 +213,11 @@ func (f *Frame) CacheSize() uint32 {
// Options returns all options for this frame.
func (f *Frame) Options() FrameOptions {
f.mu.Lock()
defer f.mu.Unlock()
return f.options()
}
func (f *Frame) options() FrameOptions {
opt := FrameOptions{
RowLabel: f.rowLabel,
InverseEnabled: f.inverseEnabled,
@ -221,7 +226,6 @@ func (f *Frame) Options() FrameOptions {
CacheSize: f.cacheSize,
TimeQuantum: f.timeQuantum,
}
f.mu.Unlock()
return opt
}
@ -329,14 +333,8 @@ func (f *Frame) loadMeta() error {
// saveMeta writes meta data for the frame.
func (f *Frame) saveMeta() error {
// Marshal metadata.
buf, err := proto.Marshal(&internal.FrameMeta{
RowLabel: f.rowLabel,
InverseEnabled: f.inverseEnabled,
RangeEnabled: f.rangeEnabled,
CacheType: f.cacheType,
CacheSize: f.cacheSize,
TimeQuantum: string(f.timeQuantum),
})
fo := f.options()
buf, err := proto.Marshal(fo.Encode())
if err != nil {
return err
}