github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/mobile/internal/binres/data.go (about) 1 // Copyright 2015 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package binres 6 7 type DataType uint8 8 9 // explicitly defined for clarity and resolvability with apt source 10 const ( 11 DataNull DataType = 0x00 // either 0 or 1 for resource undefined or empty 12 DataReference DataType = 0x01 // ResTable_ref, a reference to another resource table entry 13 DataAttribute DataType = 0x02 // attribute resource identifier 14 DataString DataType = 0x03 // index into the containing resource table's global value string pool 15 DataFloat DataType = 0x04 // single-precision floating point number 16 DataDimension DataType = 0x05 // complex number encoding a dimension value, such as "100in" 17 DataFraction DataType = 0x06 // complex number encoding a fraction of a container 18 DataDynamicReference DataType = 0x07 // dynamic ResTable_ref, which needs to be resolved before it can be used like a TYPE_REFERENCE. 19 DataIntDec DataType = 0x10 // raw integer value of the form n..n 20 DataIntHex DataType = 0x11 // raw integer value of the form 0xn..n 21 DataIntBool DataType = 0x12 // either 0 or 1, for input "false" or "true" 22 DataIntColorARGB8 DataType = 0x1c // raw integer value of the form #aarrggbb 23 DataIntColorRGB8 DataType = 0x1d // raw integer value of the form #rrggbb 24 DataIntColorARGB4 DataType = 0x1e // raw integer value of the form #argb 25 DataIntColorRGB4 DataType = 0x1f // raw integer value of the form #rgb 26 ) 27 28 type Data struct { 29 ByteSize uint16 30 Res0 uint8 // always 0, useful for debugging bad read offsets 31 Type DataType 32 Value uint32 33 } 34 35 func (d *Data) UnmarshalBinary(bin []byte) error { 36 d.ByteSize = btou16(bin) 37 d.Res0 = uint8(bin[2]) 38 d.Type = DataType(bin[3]) 39 d.Value = btou32(bin[4:]) 40 return nil 41 } 42 43 func (d *Data) MarshalBinary() ([]byte, error) { 44 bin := make([]byte, 8) 45 putu16(bin, d.ByteSize) 46 bin[2] = byte(d.Res0) 47 bin[3] = byte(d.Type) 48 putu32(bin[4:], d.Value) 49 return bin, nil 50 }