|
|
@@ -47,39 +47,39 @@ func readToc(data []byte, offset uint64) (*Toc, error) { |
|
|
return (*Toc)(unsafe.Pointer(&data[offset])), nil
|
|
|
}
|
|
|
|
|
|
-func readInstance(data []byte, offset uint64) (*Instance, error) {
|
|
|
+func readInstance(data []byte, offset uint64) (interface{}, error) {
|
|
|
if uint64(len(data)) < offset+InstanceLength {
|
|
|
return nil, errors.New("Incomplete/Partially Written Instance")
|
|
|
}
|
|
|
|
|
|
return (*Instance)(unsafe.Pointer(&data[offset])), nil
|
|
|
}
|
|
|
|
|
|
-func readInstanceDomain(data []byte, offset uint64) (*InstanceDomain, error) {
|
|
|
+func readInstanceDomain(data []byte, offset uint64) (interface{}, error) {
|
|
|
if uint64(len(data)) < offset+InstanceDomainLength {
|
|
|
return nil, errors.New("Incomplete/Partially Written InstanceDomain")
|
|
|
}
|
|
|
|
|
|
return (*InstanceDomain)(unsafe.Pointer(&data[offset])), nil
|
|
|
}
|
|
|
|
|
|
-func readMetric(data []byte, offset uint64) (*Metric, error) {
|
|
|
+func readMetric(data []byte, offset uint64) (interface{}, error) {
|
|
|
if uint64(len(data)) < offset+MetricLength {
|
|
|
return nil, errors.New("Incomplete/Partially Written Metric")
|
|
|
}
|
|
|
|
|
|
return (*Metric)(unsafe.Pointer(&data[offset])), nil
|
|
|
}
|
|
|
|
|
|
-func readValue(data []byte, offset uint64) (*Value, error) {
|
|
|
+func readValue(data []byte, offset uint64) (interface{}, error) {
|
|
|
if uint64(len(data)) < offset+ValueLength {
|
|
|
return nil, errors.New("Incomplete/Partially Written Value")
|
|
|
}
|
|
|
|
|
|
return (*Value)(unsafe.Pointer(&data[offset])), nil
|
|
|
}
|
|
|
|
|
|
-func readString(data []byte, offset uint64) (*String, error) {
|
|
|
+func readString(data []byte, offset uint64) (interface{}, error) {
|
|
|
if uint64(len(data)) < offset+StringLength {
|
|
|
return nil, errors.New("Incomplete/Partially Written String")
|
|
|
}
|
|
|
@@ -101,24 +101,24 @@ func readTocs(data []byte, count int32) ([]*Toc, error) { |
|
|
return tocs, nil
|
|
|
}
|
|
|
|
|
|
-func readInstances(data []byte, offset uint64, count int32) (map[uint64]*Instance, error) {
|
|
|
+func readItems(data []byte, offset uint64, count int32, itemlength uint64, readItem func([]byte, uint64) (interface{}, error)) (map[uint64]interface{}, error) {
|
|
|
var wg sync.WaitGroup
|
|
|
wg.Add(int(count))
|
|
|
|
|
|
- instances := make(map[uint64]*Instance)
|
|
|
+ items := make(map[uint64]interface{})
|
|
|
|
|
|
var (
|
|
|
err error
|
|
|
m sync.Mutex
|
|
|
)
|
|
|
|
|
|
- for i := int32(0); i < count; i, offset = i+1, offset+InstanceLength {
|
|
|
+ for i := int32(0); i < count; i, offset = i+1, offset+itemlength {
|
|
|
go func(offset uint64) {
|
|
|
if err == nil {
|
|
|
- instance, ierr := readInstance(data, offset)
|
|
|
+ item, ierr := readItem(data, offset)
|
|
|
if ierr == nil {
|
|
|
m.Lock()
|
|
|
- instances[offset] = instance
|
|
|
+ items[offset] = item
|
|
|
m.Unlock()
|
|
|
} else {
|
|
|
err = ierr
|
|
|
@@ -134,151 +134,7 @@ func readInstances(data []byte, offset uint64, count int32) (map[uint64]*Instanc |
|
|
return nil, err
|
|
|
}
|
|
|
|
|
|
- return instances, nil
|
|
|
-}
|
|
|
-
|
|
|
-func readInstanceDomains(data []byte, offset uint64, count int32) (map[uint64]*InstanceDomain, error) {
|
|
|
- var wg sync.WaitGroup
|
|
|
- wg.Add(int(count))
|
|
|
-
|
|
|
- indoms := make(map[uint64]*InstanceDomain)
|
|
|
-
|
|
|
- var (
|
|
|
- err error
|
|
|
- m sync.Mutex
|
|
|
- )
|
|
|
-
|
|
|
- for i := int32(0); i < count; i, offset = i+1, offset+InstanceDomainLength {
|
|
|
- go func(offset uint64) {
|
|
|
- if err == nil {
|
|
|
- indom, ierr := readInstanceDomain(data, offset)
|
|
|
- if ierr == nil {
|
|
|
- m.Lock()
|
|
|
- indoms[offset] = indom
|
|
|
- m.Unlock()
|
|
|
- } else {
|
|
|
- err = ierr
|
|
|
- }
|
|
|
- }
|
|
|
- wg.Done()
|
|
|
- }(offset)
|
|
|
- }
|
|
|
-
|
|
|
- wg.Wait()
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- return indoms, nil
|
|
|
-}
|
|
|
-
|
|
|
-func readMetrics(data []byte, offset uint64, count int32) (map[uint64]*Metric, error) {
|
|
|
- var wg sync.WaitGroup
|
|
|
- wg.Add(int(count))
|
|
|
-
|
|
|
- metrics := make(map[uint64]*Metric)
|
|
|
-
|
|
|
- var (
|
|
|
- err error
|
|
|
- m sync.Mutex
|
|
|
- )
|
|
|
-
|
|
|
- for i := int32(0); i < count; i, offset = i+1, offset+MetricLength {
|
|
|
- go func(offset uint64) {
|
|
|
- if err == nil {
|
|
|
- metric, merr := readMetric(data, offset)
|
|
|
- if merr == nil {
|
|
|
- m.Lock()
|
|
|
- metrics[offset] = metric
|
|
|
- m.Unlock()
|
|
|
- } else {
|
|
|
- err = merr
|
|
|
- }
|
|
|
- }
|
|
|
- wg.Done()
|
|
|
- }(offset)
|
|
|
- }
|
|
|
-
|
|
|
- wg.Wait()
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- return metrics, nil
|
|
|
-}
|
|
|
-
|
|
|
-func readValues(data []byte, offset uint64, count int32) (map[uint64]*Value, error) {
|
|
|
- var wg sync.WaitGroup
|
|
|
- wg.Add(int(count))
|
|
|
-
|
|
|
- values := make(map[uint64]*Value)
|
|
|
-
|
|
|
- var (
|
|
|
- err error
|
|
|
- m sync.Mutex
|
|
|
- )
|
|
|
-
|
|
|
- for i := int32(0); i < count; i, offset = i+1, offset+ValueLength {
|
|
|
- go func(offset uint64) {
|
|
|
- if err == nil {
|
|
|
- value, verr := readValue(data, offset)
|
|
|
- if verr == nil {
|
|
|
- m.Lock()
|
|
|
- values[offset] = value
|
|
|
- m.Unlock()
|
|
|
- } else {
|
|
|
- err = verr
|
|
|
- }
|
|
|
- }
|
|
|
- wg.Done()
|
|
|
- }(offset)
|
|
|
- }
|
|
|
-
|
|
|
- wg.Wait()
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- return values, nil
|
|
|
-}
|
|
|
-
|
|
|
-func readStrings(data []byte, offset uint64, count int32) (map[uint64]*String, error) {
|
|
|
- var wg sync.WaitGroup
|
|
|
- wg.Add(int(count))
|
|
|
-
|
|
|
- strings := make(map[uint64]*String)
|
|
|
-
|
|
|
- var (
|
|
|
- err error
|
|
|
- m sync.Mutex
|
|
|
- )
|
|
|
-
|
|
|
- for i := int32(0); i < count; i, offset = i+1, offset+StringLength {
|
|
|
- go func(offset uint64) {
|
|
|
- if err == nil {
|
|
|
- str, serr := readString(data, offset)
|
|
|
- if serr == nil {
|
|
|
- m.Lock()
|
|
|
- strings[offset] = str
|
|
|
- m.Unlock()
|
|
|
- } else {
|
|
|
- err = serr
|
|
|
- }
|
|
|
- }
|
|
|
- wg.Done()
|
|
|
- }(offset)
|
|
|
- }
|
|
|
-
|
|
|
- wg.Wait()
|
|
|
-
|
|
|
- if err != nil {
|
|
|
- return nil, err
|
|
|
- }
|
|
|
-
|
|
|
- return strings, nil
|
|
|
+ return items, nil
|
|
|
}
|
|
|
|
|
|
func readComponents(data []byte, tocs []*Toc) (
|
|
|
@@ -292,31 +148,59 @@ func readComponents(data []byte, tocs []*Toc) ( |
|
|
var wg sync.WaitGroup
|
|
|
wg.Add(len(tocs))
|
|
|
|
|
|
+ var (
|
|
|
+ tmetrics map[uint64]interface{}
|
|
|
+ tvalues map[uint64]interface{}
|
|
|
+ tinstances map[uint64]interface{}
|
|
|
+ tindoms map[uint64]interface{}
|
|
|
+ tstrings map[uint64]interface{}
|
|
|
+ )
|
|
|
+
|
|
|
for _, toc := range tocs {
|
|
|
switch toc.Type {
|
|
|
case TocInstances:
|
|
|
go func(offset uint64, count int32) {
|
|
|
- instances, ierr = readInstances(data, offset, count)
|
|
|
+ tinstances, ierr = readItems(data, offset, count, InstanceLength, readInstance)
|
|
|
+ instances = make(map[uint64]*Instance)
|
|
|
+ for off, val := range tinstances {
|
|
|
+ instances[off] = val.(*Instance)
|
|
|
+ }
|
|
|
wg.Done()
|
|
|
}(toc.Offset, toc.Count)
|
|
|
case TocIndoms:
|
|
|
go func(offset uint64, count int32) {
|
|
|
- indoms, inerr = readInstanceDomains(data, offset, count)
|
|
|
+ tindoms, inerr = readItems(data, offset, count, InstanceDomainLength, readInstanceDomain)
|
|
|
+ indoms = make(map[uint64]*InstanceDomain)
|
|
|
+ for off, val := range tindoms {
|
|
|
+ indoms[off] = val.(*InstanceDomain)
|
|
|
+ }
|
|
|
wg.Done()
|
|
|
}(toc.Offset, toc.Count)
|
|
|
case TocMetrics:
|
|
|
go func(offset uint64, count int32) {
|
|
|
- metrics, merr = readMetrics(data, offset, count)
|
|
|
+ tmetrics, merr = readItems(data, offset, count, MetricLength, readMetric)
|
|
|
+ metrics = make(map[uint64]*Metric)
|
|
|
+ for off, val := range tmetrics {
|
|
|
+ metrics[off] = val.(*Metric)
|
|
|
+ }
|
|
|
wg.Done()
|
|
|
}(toc.Offset, toc.Count)
|
|
|
case TocValues:
|
|
|
go func(offset uint64, count int32) {
|
|
|
- values, verr = readValues(data, offset, count)
|
|
|
+ tvalues, verr = readItems(data, offset, count, ValueLength, readValue)
|
|
|
+ values = make(map[uint64]*Value)
|
|
|
+ for off, val := range tvalues {
|
|
|
+ values[off] = val.(*Value)
|
|
|
+ }
|
|
|
wg.Done()
|
|
|
}(toc.Offset, toc.Count)
|
|
|
case TocStrings:
|
|
|
go func(offset uint64, count int32) {
|
|
|
- strings, serr = readStrings(data, offset, count)
|
|
|
+ tstrings, serr = readItems(data, offset, count, StringLength, readString)
|
|
|
+ strings = make(map[uint64]*String)
|
|
|
+ for off, val := range tstrings {
|
|
|
+ strings[off] = val.(*String)
|
|
|
+ }
|
|
|
wg.Done()
|
|
|
}(toc.Offset, toc.Count)
|
|
|
}
|
|
|
|
0 comments on commit
8189196