package com.google.firebase.encoders.proto; import com.google.firebase.encoders.EncodingException; import com.google.firebase.encoders.ObjectEncoder; import com.google.firebase.encoders.ObjectEncoderContext; import com.google.firebase.encoders.ValueEncoder; import com.google.firebase.encoders.config.Configurator; import com.google.firebase.encoders.config.EncoderConfig; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; /* loaded from: classes3.dex */ public class ProtobufEncoder { private final ObjectEncoder fallbackEncoder; private final Map, ObjectEncoder> objectEncoders; private final Map, ValueEncoder> valueEncoders; public ProtobufEncoder(Map, ObjectEncoder> map, Map, ValueEncoder> map2, ObjectEncoder objectEncoder) { this.objectEncoders = map; this.valueEncoders = map2; this.fallbackEncoder = objectEncoder; } public static Builder builder() { return new Builder(); } public void encode(Object obj, OutputStream outputStream) throws IOException { new ProtobufDataEncoderContext(outputStream, this.objectEncoders, this.valueEncoders, this.fallbackEncoder).encode(obj); } /* loaded from: classes3.dex */ public static final class Builder implements EncoderConfig { private static final ObjectEncoder DEFAULT_FALLBACK_ENCODER = new a(1); private final Map, ObjectEncoder> objectEncoders = new HashMap(); private final Map, ValueEncoder> valueEncoders = new HashMap(); private ObjectEncoder fallbackEncoder = DEFAULT_FALLBACK_ENCODER; public static /* synthetic */ void lambda$static$0(Object obj, ObjectEncoderContext objectEncoderContext) throws IOException { throw new EncodingException("Couldn't find encoder for type " + obj.getClass().getCanonicalName()); } public ProtobufEncoder build() { return new ProtobufEncoder(new HashMap(this.objectEncoders), new HashMap(this.valueEncoders), this.fallbackEncoder); } public Builder configureWith(Configurator configurator) { configurator.configure(this); return this; } public Builder registerFallbackEncoder(ObjectEncoder objectEncoder) { this.fallbackEncoder = objectEncoder; return this; } @Override // com.google.firebase.encoders.config.EncoderConfig public Builder registerEncoder(Class cls, ObjectEncoder objectEncoder) { this.objectEncoders.put(cls, objectEncoder); this.valueEncoders.remove(cls); return this; } @Override // com.google.firebase.encoders.config.EncoderConfig public Builder registerEncoder(Class cls, ValueEncoder valueEncoder) { this.valueEncoders.put(cls, valueEncoder); this.objectEncoders.remove(cls); return this; } } public byte[] encode(Object obj) { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); try { encode(obj, byteArrayOutputStream); } catch (IOException unused) { } return byteArrayOutputStream.toByteArray(); } }