blob: 88a78e4a35b4f72e1ab4d8a785a31e3fbb26c46e [file] [log] [blame]
// Copyright (C) 2014 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.
{{define "Enum"}}{{.Name}}Enum{{end}}
{{define "ID"}}{{.Name}}ID{{end}}
{{define "IDBytes"}}{{.Name}}IDBytes{{end}}
{{define "Encoder"}}
public static void encode(Encoder e, {{class .Name}} o) throws IOException {
{{range .Fields}} {{encode (print "o." (fieldname .Name)) .Type}}
{{end}} }{{end}}
{{define "EncodeNative"}}e.{{lower .Type.Method}}({{.Name}});{{end}}
{{define "EncodeRemap"}}{{.Name}}.encode(e);{{end}}
{{define "EncodeCodeable"}}{{.Name}}.encode(e);{{end}}
{{define "EncodeObject"}}e.object({{.Name}});{{end}}
{{define "EncodeArray"}}e.int32({{.Name}}.length);
for (int i = 0; i < {{.Name}}.length; i++) {
{{encode (print .Name "[i]") .Type.SubType}}
}{{end}}
{{define "Decoder"}}
public static void decode(Decoder d, {{class .Name}} o) throws IOException {
{{range .Fields}} {{decode (print "o." (fieldname .Name)) .Type}}
{{end}} }{{end}}
{{define "DecodeNative"}}{{.Name}} = d.{{lower .Type.Method}}();{{end}}
{{define "DecodeRemap"}}{{.Name}} = {{.Type.Name}}.decode(d);{{end}}
{{define "DecodeCodeable"}}{{.Name}} = new {{.Type.Name}}(d);{{end}}
{{define "DecodeObject"}}{{.Name}} = ({{storage .Type}})d.object();{{end}}
{{define "DecodeArray"}}{{.Name}} = new {{storage .Type.SubType}}[d.int32()];
for (int i = 0; i < {{.Name}}.length; i++) {
{{decode (print .Name "[i]") .Type.SubType}}
}{{end}}
{{define "File"}}/*
* Copyright (C) 2015 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.
*
* THIS WILL BE REMOVED ONCE THE CODE GENERATOR IS INTEGRATED INTO THE BUILD.
*/
package {{.Package}};
import com.android.tools.rpclib.binary.BinaryObject;
import com.android.tools.rpclib.binary.BinaryObjectCreator;
import com.android.tools.rpclib.binary.Decoder;
import com.android.tools.rpclib.binary.Encoder;
import com.android.tools.rpclib.binary.ObjectTypeID;
import java.io.IOException;
class ObjectFactory {
public enum Entries implements BinaryObjectCreator {{"{"}}{{range .Structs}}
{{template "Enum" .}} {
@Override public BinaryObject create() {
return new {{class .Name}}();
}
},{{end}}
}
{{range .Structs}}
public static byte[] {{template "IDBytes" .}} = { {{range .ID}}{{toS8 .}}, {{end}}{{"}"}};{{end}}
{{range .Structs}}
public static ObjectTypeID {{template "ID" .}} = new ObjectTypeID({{template "IDBytes" .}});{{end}}
static {{"{"}}{{range .Structs}}
ObjectTypeID.register({{template "ID" .}}, Entries.{{template "Enum" .}});{{end}}
}{{range .Structs}}
{{template "Encoder" .}}
{{template "Decoder" .}}{{end}}
}
{{end}}