diff options
author | Ian Cottrell <iancottrell@google.com> | 2015-03-06 13:11:16 +0000 |
---|---|---|
committer | Ian Cottrell <iancottrell@google.com> | 2015-03-10 16:55:28 +0000 |
commit | be6611c84c352f25b008cfe6d041fb3b7cc728ff (patch) | |
tree | e46490fbcf2dee8f1a9c3b07ad8312133bebedef /atom | |
parent | 4a65fc044037f8f70791b6fea758782329f862fa (diff) | |
download | gpu-be6611c84c352f25b008cfe6d041fb3b7cc728ff.tar.gz |
Fix atom streams
Remove the atom sizes from the stream
Prepend the stream with a count of atoms
Add an id type to the schema
Fix the schema to include return parameters
Add the resource id to the memory observation schema
Change-Id: I21322f47834470feb8a05927e4f4388ea2c815cc
Diffstat (limited to 'atom')
-rw-r--r-- | atom/list.go | 53 | ||||
-rw-r--r-- | atom/list_test.go | 7 |
2 files changed, 16 insertions, 44 deletions
diff --git a/atom/list.go b/atom/list.go index 95e3e0409..28ee67caf 100644 --- a/atom/list.go +++ b/atom/list.go @@ -14,11 +14,7 @@ package atom -import ( - "bytes" - - "android.googlesource.com/platform/tools/gpu/binary" -) +import "android.googlesource.com/platform/tools/gpu/binary" // List is a list of atoms. type List []Atom @@ -65,62 +61,41 @@ 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 { - atomBuf := &bytes.Buffer{} - atomEnc := binary.NewEncoder(atomBuf) + if err := e.Uint32(uint32(len(*l))); err != nil { + return err + } for _, atom := range *l { - if err := atom.TypeID().Encode(atomEnc); err != nil { - return err - } - - if err := atom.Encode(atomEnc); err != nil { + if err := atom.TypeID().Encode(e); err != nil { return err } - - atomData := atomBuf.Bytes() - if err := e.Uint16(uint16(len(atomData) + 2)); err != nil { + if err := atom.Encode(e); err != nil { return err } - - if _, err := e.Write(atomData); err != nil { - return err - } - atomBuf.Reset() } - - e.Uint16(0) return nil } // Encode decodes the atom list using the specified encoder. func (l *List) Decode(d *binary.Decoder) error { - *l = List{} // Clear the list - - for { - size, err := d.Uint16() - if err != nil { - return err - } - - if size == 0 { - break - } - + count, err := d.Uint32() + if err != nil { + *l = List{} // Clear the list + return err + } + *l = make(List, count) + for i := range *l { var typeID TypeID if err := typeID.Decode(d); err != nil { return err } - atom, err := New(TypeID(typeID)) if err != nil { return err } - if err := atom.Decode(d); err != nil { return err } - - *l = append(*l, atom) + (*l)[i] = atom } - return nil } diff --git a/atom/list_test.go b/atom/list_test.go index c9984a99f..8b5a5dcee 100644 --- a/atom/list_test.go +++ b/atom/list_test.go @@ -28,22 +28,19 @@ var testList = List{ &testAtomC{Context: 0x10, String: "Pizza"}, } var testData = []byte{ - 0x06, // Atom 0: Size (+2 for type) + 0x03, // Atom count + 0x0a, // Atom 0: Type 0x10, // Atom 0: Context 0x80, 0xc8, // Atom 0: Data - 0x05, // Atom 1: Size (+2 for type) 0x14, // Atom 1: Type 0x20, // Atom 1: Context 0x01, // Atom 1: Data - 0x0a, // Atom 2: Size (+2 for type) 0x1e, // Atom 2: Type 0x10, // Atom 2: Context 0x05, 'P', 'i', 'z', 'z', 'a', // Atom 2: Data - - 0x00, // EOS 0 } func TestAtomListEncode(t *testing.T) { |