diff options
author | Ian Cottrell <iancottrell@google.com> | 2015-03-18 17:31:07 +0000 |
---|---|---|
committer | Ian Cottrell <iancottrell@google.com> | 2015-03-20 12:47:12 +0000 |
commit | ac761a60af2f126ed80d9a29b5c328bf74163efa (patch) | |
tree | 603ec167d9d7a84ba2e40863d00904a95df97a37 /atom | |
parent | 04872aaa44c69d3adce68feb0b4c613c2fd61be4 (diff) | |
download | gpu-ac761a60af2f126ed80d9a29b5c328bf74163efa.tar.gz |
Split the variable size integer writer from the object hierarchy encoder
Change-Id: I587cc45e08d2b49a88b93e1816d0a22def405356
Diffstat (limited to 'atom')
-rwxr-xr-x | atom/atom_binary.go | 19 | ||||
-rw-r--r-- | atom/atom_test.go | 12 | ||||
-rw-r--r-- | atom/list.go | 4 | ||||
-rw-r--r-- | atom/list_test.go | 7 | ||||
-rw-r--r-- | atom/registry.go | 8 | ||||
-rw-r--r-- | atom/transform/common_test.go | 10 |
6 files changed, 31 insertions, 29 deletions
diff --git a/atom/atom_binary.go b/atom/atom_binary.go index ccefcbc96..d24c66885 100755 --- a/atom/atom_binary.go +++ b/atom/atom_binary.go @@ -7,25 +7,26 @@ package atom import ( "android.googlesource.com/platform/tools/gpu/binary" + "android.googlesource.com/platform/tools/gpu/binary/registry" ) func init() { //struct atom.EOS { Context:ContextID } - binary.Register(binary.ID{0xb5, 0x85, 0xac, 0x22, 0x71, 0xd1, 0x84, 0x5c, 0xc0, 0x70, 0x37, 0x53, 0x35, 0x88, 0x2e, 0x3e, 0x5a, 0x27, 0xa3, 0xcd}, &EOS{}) + registry.Add(binary.ID{0xb5, 0x85, 0xac, 0x22, 0x71, 0xd1, 0x84, 0x5c, 0xc0, 0x70, 0x37, 0x53, 0x35, 0x88, 0x2e, 0x3e, 0x5a, 0x27, 0xa3, 0xcd}, &EOS{}) //struct atom.Group { Name:string, Range:Range, SubGroups:GroupList } - binary.Register(binary.ID{0x1d, 0x80, 0xcc, 0xfa, 0xe5, 0xba, 0x0e, 0x88, 0x3f, 0x11, 0x3b, 0xd5, 0x07, 0x16, 0x56, 0x13, 0xf5, 0x43, 0x42, 0xeb}, &Group{}) + registry.Add(binary.ID{0x1d, 0x80, 0xcc, 0xfa, 0xe5, 0xba, 0x0e, 0x88, 0x3f, 0x11, 0x3b, 0xd5, 0x07, 0x16, 0x56, 0x13, 0xf5, 0x43, 0x42, 0xeb}, &Group{}) //struct atom.Range { Start:ID, End:ID } - binary.Register(binary.ID{0x6f, 0xbb, 0x0f, 0x69, 0x4c, 0x19, 0xdb, 0x86, 0x34, 0x4f, 0x63, 0xc3, 0x04, 0xaf, 0x06, 0x89, 0xda, 0x0f, 0xb3, 0x0a}, &Range{}) + registry.Add(binary.ID{0x6f, 0xbb, 0x0f, 0x69, 0x4c, 0x19, 0xdb, 0x86, 0x34, 0x4f, 0x63, 0xc3, 0x04, 0xaf, 0x06, 0x89, 0xda, 0x0f, 0xb3, 0x0a}, &Range{}) } -func (o EOS) Encode(e *binary.Encoder) error { +func (o EOS) Encode(e binary.Encoder) error { if err := e.Uint32(uint32(o.Context)); err != nil { return err } return nil } -func (o *EOS) Decode(d *binary.Decoder) error { +func (o *EOS) Decode(d binary.Decoder) error { if obj, err := d.Uint32(); err != nil { return err } else { @@ -34,7 +35,7 @@ func (o *EOS) Decode(d *binary.Decoder) error { return nil } -func (o Group) Encode(e *binary.Encoder) error { +func (o Group) Encode(e binary.Encoder) error { if err := e.String(o.Name); err != nil { return err } @@ -52,7 +53,7 @@ func (o Group) Encode(e *binary.Encoder) error { return nil } -func (o *Group) Decode(d *binary.Decoder) error { +func (o *Group) Decode(d binary.Decoder) error { if obj, err := d.String(); err != nil { return err } else { @@ -74,7 +75,7 @@ func (o *Group) Decode(d *binary.Decoder) error { return nil } -func (o Range) Encode(e *binary.Encoder) error { +func (o Range) Encode(e binary.Encoder) error { if err := e.Uint64(uint64(o.Start)); err != nil { return err } @@ -84,7 +85,7 @@ func (o Range) Encode(e *binary.Encoder) error { return nil } -func (o *Range) Decode(d *binary.Decoder) error { +func (o *Range) Decode(d binary.Decoder) error { if obj, err := d.Uint64(); err != nil { return err } else { diff --git a/atom/atom_test.go b/atom/atom_test.go index 6149b5cdf..a002f06f3 100644 --- a/atom/atom_test.go +++ b/atom/atom_test.go @@ -29,13 +29,13 @@ func (testAtomA) TypeID() TypeID { return testAtomIDA } func (a *testAtomA) ContextID() ContextID { return a.Context } func (a *testAtomA) Info() string { return "" } func (a *testAtomA) Flags() Flags { return 0 } -func (a *testAtomA) Encode(e *binary.Encoder) error { +func (a *testAtomA) Encode(e binary.Encoder) error { if err := e.Uint32(uint32(a.Context)); err != nil { return err } return e.Int32(a.Int32) } -func (a *testAtomA) Decode(d *binary.Decoder) (err error) { +func (a *testAtomA) Decode(d binary.Decoder) (err error) { if obj, err := d.Uint32(); err != nil { return err } else { @@ -54,13 +54,13 @@ func (testAtomB) TypeID() TypeID { return testAtomIDB } func (a *testAtomB) ContextID() ContextID { return a.Context } func (a *testAtomB) Info() string { return "" } func (a *testAtomB) Flags() Flags { return 0 } -func (a *testAtomB) Encode(e *binary.Encoder) error { +func (a *testAtomB) Encode(e binary.Encoder) error { if err := e.Uint32(uint32(a.Context)); err != nil { return err } return e.Bool(a.Bool) } -func (a *testAtomB) Decode(d *binary.Decoder) (err error) { +func (a *testAtomB) Decode(d binary.Decoder) (err error) { if obj, err := d.Uint32(); err != nil { return err } else { @@ -79,13 +79,13 @@ func (testAtomC) TypeID() TypeID { return testAtomIDC } func (a *testAtomC) ContextID() ContextID { return a.Context } func (a *testAtomC) Info() string { return "" } func (a *testAtomC) Flags() Flags { return 0 } -func (a *testAtomC) Encode(e *binary.Encoder) error { +func (a *testAtomC) Encode(e binary.Encoder) error { if err := e.Uint32(uint32(a.Context)); err != nil { return err } return e.String(a.String) } -func (a *testAtomC) Decode(d *binary.Decoder) (err error) { +func (a *testAtomC) Decode(d binary.Decoder) (err error) { if obj, err := d.Uint32(); err != nil { return err } else { diff --git a/atom/list.go b/atom/list.go index 733898e11..e11386174 100644 --- a/atom/list.go +++ b/atom/list.go @@ -60,7 +60,7 @@ func (l *List) AddAt(a Atom, id ID) { } // Encode encodes the atom list using the specified encoder. -func (l *List) Encode(e *binary.Encoder) error { +func (l *List) Encode(e binary.Encoder) error { if err := e.Uint32(uint32(len(*l))); err != nil { return err } @@ -76,7 +76,7 @@ func (l *List) Encode(e *binary.Encoder) error { } // Encode decodes the atom list using the specified encoder. -func (l *List) Decode(d *binary.Decoder) error { +func (l *List) Decode(d binary.Decoder) error { count, err := d.Uint32() if err != nil { *l = List{} // Clear the list diff --git a/atom/list_test.go b/atom/list_test.go index 8b5a5dcee..01d4d8b34 100644 --- a/atom/list_test.go +++ b/atom/list_test.go @@ -19,7 +19,8 @@ import ( "reflect" "testing" - "android.googlesource.com/platform/tools/gpu/binary" + "android.googlesource.com/platform/tools/gpu/binary/cyclic" + "android.googlesource.com/platform/tools/gpu/binary/vle" ) var testList = List{ @@ -45,7 +46,7 @@ var testData = []byte{ func TestAtomListEncode(t *testing.T) { buf := &bytes.Buffer{} - enc := binary.NewEncoder(buf) + enc := cyclic.Encoder(vle.Writer(buf)) err := testList.Encode(enc) if err != nil { t.Errorf("Encode returned unexpected error: %v", err) @@ -58,7 +59,7 @@ func TestAtomListEncode(t *testing.T) { func TestAtomListDecode(t *testing.T) { list := List{} - err := list.Decode(binary.NewDecoder(bytes.NewBuffer(testData))) + err := list.Decode(cyclic.Decoder(vle.Reader(bytes.NewBuffer(testData)))) if err != nil { t.Errorf("Decode returned unexpected error: %v", err) } diff --git a/atom/registry.go b/atom/registry.go index 2f0999a03..f1fd5d701 100644 --- a/atom/registry.go +++ b/atom/registry.go @@ -16,21 +16,21 @@ package atom import "fmt" -var registry = map[TypeID]TypeInfo{} +var atomRegistry = map[TypeID]TypeInfo{} // Register registers the atom type ty with the atom registry. If another atom // is already registered with the same type identifer then Register will panic. func Register(ty TypeInfo) { - if _, dup := registry[ty.ID]; dup { + if _, dup := atomRegistry[ty.ID]; dup { panic(fmt.Errorf("Duplicate atom type id 0x%x registered", ty.ID)) } - registry[ty.ID] = ty + atomRegistry[ty.ID] = ty } // New builds a new instance of the atom with type identifier id. The type must // have previously been registered with Register. func New(id TypeID) (Atom, error) { - if ty, ok := registry[id]; ok { + if ty, ok := atomRegistry[id]; ok { return ty.New(), nil } else { return nil, fmt.Errorf("Atom type id 0x%x not registered", id) diff --git a/atom/transform/common_test.go b/atom/transform/common_test.go index e01b041fc..905da09da 100644 --- a/atom/transform/common_test.go +++ b/atom/transform/common_test.go @@ -29,11 +29,11 @@ type testAtom struct { AtomFlags atom.Flags } -func (a testAtom) TypeID() atom.TypeID { return a.Type } -func (a testAtom) ContextID() atom.ContextID { return a.Context } -func (a testAtom) Flags() atom.Flags { return a.AtomFlags } -func (a testAtom) Encode(*binary.Encoder) error { return nil } -func (a testAtom) Decode(*binary.Decoder) error { return nil } +func (a testAtom) TypeID() atom.TypeID { return a.Type } +func (a testAtom) ContextID() atom.ContextID { return a.Context } +func (a testAtom) Flags() atom.Flags { return a.AtomFlags } +func (a testAtom) Encode(binary.Encoder) error { return nil } +func (a testAtom) Decode(binary.Decoder) error { return nil } type atomAtomIDList []atomAtomID |