1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.modules.utils; 18 19 import android.annotation.NonNull; 20 import android.annotation.Nullable; 21 22 import org.xmlpull.v1.XmlSerializer; 23 24 import java.io.IOException; 25 26 /** 27 * Specialization of {@link XmlSerializer} which adds explicit methods to 28 * support consistent and efficient conversion of primitive data types. 29 */ 30 public interface TypedXmlSerializer extends XmlSerializer { 31 /** 32 * Functionally equivalent to {@link #attribute(String, String, String)} but 33 * with the additional signal that the given value is a candidate for being 34 * canonicalized, similar to {@link String#intern()}. 35 */ attributeInterned(@ullable String namespace, @NonNull String name, @NonNull String value)36 @NonNull XmlSerializer attributeInterned(@Nullable String namespace, @NonNull String name, 37 @NonNull String value) throws IOException; 38 39 /** 40 * Encode the given strongly-typed value and serialize using 41 * {@link #attribute(String, String, String)}. 42 */ attributeBytesHex(@ullable String namespace, @NonNull String name, @NonNull byte[] value)43 @NonNull XmlSerializer attributeBytesHex(@Nullable String namespace, @NonNull String name, 44 @NonNull byte[] value) throws IOException; 45 46 /** 47 * Encode the given strongly-typed value and serialize using 48 * {@link #attribute(String, String, String)}. 49 */ attributeBytesBase64(@ullable String namespace, @NonNull String name, @NonNull byte[] value)50 @NonNull XmlSerializer attributeBytesBase64(@Nullable String namespace, @NonNull String name, 51 @NonNull byte[] value) throws IOException; 52 53 /** 54 * Encode the given strongly-typed value and serialize using 55 * {@link #attribute(String, String, String)}. 56 */ attributeInt(@ullable String namespace, @NonNull String name, int value)57 @NonNull XmlSerializer attributeInt(@Nullable String namespace, @NonNull String name, 58 int value) throws IOException; 59 60 /** 61 * Encode the given strongly-typed value and serialize using 62 * {@link #attribute(String, String, String)}. 63 */ attributeIntHex(@ullable String namespace, @NonNull String name, int value)64 @NonNull XmlSerializer attributeIntHex(@Nullable String namespace, @NonNull String name, 65 int value) throws IOException; 66 67 /** 68 * Encode the given strongly-typed value and serialize using 69 * {@link #attribute(String, String, String)}. 70 */ attributeLong(@ullable String namespace, @NonNull String name, long value)71 @NonNull XmlSerializer attributeLong(@Nullable String namespace, @NonNull String name, 72 long value) throws IOException; 73 74 /** 75 * Encode the given strongly-typed value and serialize using 76 * {@link #attribute(String, String, String)}. 77 */ attributeLongHex(@ullable String namespace, @NonNull String name, long value)78 @NonNull XmlSerializer attributeLongHex(@Nullable String namespace, @NonNull String name, 79 long value) throws IOException; 80 81 /** 82 * Encode the given strongly-typed value and serialize using 83 * {@link #attribute(String, String, String)}. 84 */ attributeFloat(@ullable String namespace, @NonNull String name, float value)85 @NonNull XmlSerializer attributeFloat(@Nullable String namespace, @NonNull String name, 86 float value) throws IOException; 87 88 /** 89 * Encode the given strongly-typed value and serialize using 90 * {@link #attribute(String, String, String)}. 91 */ attributeDouble(@ullable String namespace, @NonNull String name, double value)92 @NonNull XmlSerializer attributeDouble(@Nullable String namespace, @NonNull String name, 93 double value) throws IOException; 94 95 /** 96 * Encode the given strongly-typed value and serialize using 97 * {@link #attribute(String, String, String)}. 98 */ attributeBoolean(@ullable String namespace, @NonNull String name, boolean value)99 @NonNull XmlSerializer attributeBoolean(@Nullable String namespace, @NonNull String name, 100 boolean value) throws IOException; 101 } 102