blob: bf0039e113b03db25be10495c4858831299069b8 [file] [log] [blame]
// Copyright (C) 2016 The Android Open Source Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package stringtable
import (
"fmt"
"os"
"android.googlesource.com/platform/tools/gpu/framework/binary/cyclic"
"android.googlesource.com/platform/tools/gpu/framework/binary/endian"
"android.googlesource.com/platform/tools/gpu/framework/device"
)
// Load loads a string table from the specified path.
func Load(path string) (*StringTable, error) {
file, err := os.Open(path)
if err != nil {
return nil, err
}
defer file.Close()
d := cyclic.Decoder(endian.Reader(file, device.LittleEndian))
o := d.Object()
if err := d.Error(); err != nil {
return nil, err
}
st, ok := o.(*StringTable)
if !ok {
return nil, fmt.Errorf("Decoded object was not a stringtable, but a %T", st)
}
return st, nil
}