@@ -9,18 +9,22 @@ import (
99 "unsafe"
1010)
1111
12+ // ResID is ID for resources.
1213type ResID uint32
1314
15+ // TableFile is a resrouce table file.
1416type TableFile struct {
1517 stringPool * ResStringPool
1618 tablePackages map [uint32 ]* TablePackage
1719}
1820
21+ // ResTableHeader is a header of TableFile.
1922type ResTableHeader struct {
2023 Header ResChunkHeader
2124 PackageCount uint32
2225}
2326
27+ // ResTablePackage is a header of table packages.
2428type ResTablePackage struct {
2529 Header ResChunkHeader
2630 ID uint32
@@ -31,13 +35,15 @@ type ResTablePackage struct {
3135 LastPublicKey uint32
3236}
3337
38+ // TablePackage is a table package.
3439type TablePackage struct {
3540 Header ResTablePackage
3641 TypeStrings * ResStringPool
3742 KeyStrings * ResStringPool
3843 TableTypes []* TableType
3944}
4045
46+ // ResTableType is a type of a table.
4147type ResTableType struct {
4248 Header ResChunkHeader
4349 ID uint8
@@ -99,6 +105,7 @@ const (
99105 NAVHIDDEN_YES = 0x08
100106)
101107
108+ // ResTableConfig is a configuration of a table.
102109type ResTableConfig struct {
103110 Size uint32
104111 // imsi
@@ -138,23 +145,27 @@ type ResTableConfig struct {
138145 ScreenHeightDp uint16
139146}
140147
148+ // TableType is a collection of resource entries for a particular resource data type.
141149type TableType struct {
142150 Header * ResTableType
143151 Entries []TableEntry
144152}
145153
154+ // ResTableEntry is the beginning of information about an entry in the resource table.
146155type ResTableEntry struct {
147156 Size uint16
148157 Flags uint16
149158 Key ResStringPoolRef
150159}
151160
161+ // TableEntry is a entry in a recource table.
152162type TableEntry struct {
153163 Key * ResTableEntry
154164 Value * ResValue
155165 Flags uint32
156166}
157167
168+ // ResTableTypeSpec is specification of the resources defined by a particular type.
158169type ResTableTypeSpec struct {
159170 Header ResChunkHeader
160171 ID uint8
@@ -184,18 +195,22 @@ func (id ResID) String() string {
184195 return fmt .Sprintf ("@0x%08X" , uint32 (id ))
185196}
186197
198+ // Package returns the package index of id.
187199func (id ResID ) Package () int {
188200 return int (id ) >> 24
189201}
190202
203+ // Type returns the type index of id.
191204func (id ResID ) Type () int {
192205 return (int (id ) >> 16 ) & 0xFF
193206}
194207
208+ // Entry returns the entry index of id.
195209func (id ResID ) Entry () int {
196210 return int (id ) & 0xFFFF
197211}
198212
213+ // NewTableFile returns new TableFile.
199214func NewTableFile (r io.ReaderAt ) (* TableFile , error ) {
200215 f := new (TableFile )
201216 sr := io .NewSectionReader (r , 0 , 1 << 63 - 1 )
@@ -241,6 +256,7 @@ func (p *TablePackage) findEntry(typeIndex, entryIndex int, config *ResTableConf
241256 return best .Entries [entryIndex ]
242257}
243258
259+ // GetResource returns a resrouce referenced by id.
244260func (f * TableFile ) GetResource (id ResID , config * ResTableConfig ) (interface {}, error ) {
245261 p := f .findPackage (id .Package ())
246262 if p == nil {
@@ -266,6 +282,7 @@ func (f *TableFile) GetResource(id ResID, config *ResTableConfig) (interface{},
266282 return v .Data , nil
267283}
268284
285+ // GetString returns a string referenced by ref.
269286func (f * TableFile ) GetString (ref ResStringPoolRef ) string {
270287 return f .stringPool .GetString (ref )
271288}
@@ -413,6 +430,7 @@ func readTableTypeSpec(sr *io.SectionReader) ([]uint32, error) {
413430 return flags , nil
414431}
415432
433+ // IsMoreSpecificThan returns true if c is more specific than o.
416434func (c * ResTableConfig ) IsMoreSpecificThan (o * ResTableConfig ) bool {
417435 // nil ResTableConfig is never more specific than any ResTableConfig
418436 if c == nil {
@@ -637,6 +655,7 @@ func (c *ResTableConfig) IsMoreSpecificThan(o *ResTableConfig) bool {
637655 return false
638656}
639657
658+ // IsBetterThan returns true if c is better than o for the r configuration.
640659func (c * ResTableConfig ) IsBetterThan (o * ResTableConfig , r * ResTableConfig ) bool {
641660 if r == nil {
642661 return c .IsMoreSpecificThan (o )
@@ -842,6 +861,9 @@ func (c *ResTableConfig) IsBetterThan(o *ResTableConfig, r *ResTableConfig) bool
842861 return false
843862}
844863
864+ // IsLocaleMoreSpecificThan a positive integer if this config is more specific than o,
865+ // a negative integer if |o| is more specific
866+ // and 0 if they're equally specific.
845867func (c * ResTableConfig ) IsLocaleMoreSpecificThan (o * ResTableConfig ) int {
846868 if (c .Language != [2 ]uint8 {} || c .Country != [2 ]uint8 {}) || (o .Language != [2 ]uint8 {} || o .Country != [2 ]uint8 {}) {
847869 if c .Language != o .Language {
@@ -865,6 +887,7 @@ func (c *ResTableConfig) IsLocaleMoreSpecificThan(o *ResTableConfig) int {
865887 return 0
866888}
867889
890+ // IsLocaleBetterThan returns true if c is a better locale match than o for the r configuration.
868891func (c * ResTableConfig ) IsLocaleBetterThan (o * ResTableConfig , r * ResTableConfig ) bool {
869892 if r .Language == [2 ]uint8 {} && r .Country == [2 ]uint8 {} {
870893 // The request doesn't have a locale, so no resource is better
@@ -900,6 +923,7 @@ func (c *ResTableConfig) IsLocaleBetterThan(o *ResTableConfig, r *ResTableConfig
900923 return false
901924}
902925
926+ // Match returns true if c can be considered a match for the parameters in settings.
903927func (c * ResTableConfig ) Match (settings * ResTableConfig ) bool {
904928 // nil ResTableConfig always matches.
905929 if settings == nil {
@@ -1045,6 +1069,7 @@ func (c *ResTableConfig) Match(settings *ResTableConfig) bool {
10451069 return true
10461070}
10471071
1072+ // Locale returns the locale of the configuration.
10481073func (c * ResTableConfig ) Locale () string {
10491074 if c .Language [0 ] == 0 {
10501075 return ""
0 commit comments