-
Notifications
You must be signed in to change notification settings - Fork 7
/
Descriptors.go
44 lines (38 loc) · 1.39 KB
/
Descriptors.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package object
// Descriptors describes a set of object classes.
type Descriptors []ClassDescriptor
// ClassDescriptor describes a single object class.
type ClassDescriptor struct {
// GenericDataSize specifies the length, in bytes, of one generic type entry.
GenericDataSize int
// Subclasses contains descriptions of the subclasses of this class.
// The index into the array is the subclass ID.
Subclasses []SubclassDescriptor
}
// TotalDataSize returns the total length the class requires.
func (desc ClassDescriptor) TotalDataSize() int {
total := 0
for _, subclass := range desc.Subclasses {
total += (desc.GenericDataSize * subclass.TypeCount) + subclass.TotalDataSize()
}
return total
}
// TotalTypeCount returns the total number of types in this class.
func (desc ClassDescriptor) TotalTypeCount() int {
total := 0
for _, subclass := range desc.Subclasses {
total += subclass.TypeCount
}
return total
}
// SubclassDescriptor describes one subclass.
type SubclassDescriptor struct {
// TypeCount specifies how many types exist in this subclass.
TypeCount int
// SpecificDataSize specifies the length, in bytes, of one specific type entry.
SpecificDataSize int
}
// TotalDataSize returns the total length, in bytes, the subclass requires in the properties file.
func (desc SubclassDescriptor) TotalDataSize() int {
return (desc.SpecificDataSize + CommonPropertiesSize) * desc.TypeCount
}