// 
// Decompiled by Procyon v0.6.0
// 

package com.google.protobuf;

public final class DebugFormat
{
    private final boolean isSingleLine;
    
    private TextFormat.Printer getPrinter() {
        final TextFormat.Printer printer = TextFormat.debugFormatPrinter();
        if (this.isSingleLine) {
            return printer.emittingSingleLine(true);
        }
        return printer;
    }
    
    private DebugFormat(final boolean singleLine) {
        this.isSingleLine = singleLine;
    }
    
    public static DebugFormat singleLine() {
        return new DebugFormat(true);
    }
    
    public static DebugFormat multiline() {
        return new DebugFormat(false);
    }
    
    public String toString(final MessageOrBuilder message) {
        final TextFormat.Printer.FieldReporterLevel fieldReporterLevel = this.isSingleLine ? TextFormat.Printer.FieldReporterLevel.DEBUG_SINGLE_LINE : TextFormat.Printer.FieldReporterLevel.DEBUG_MULTILINE;
        return this.getPrinter().printToString(message, fieldReporterLevel);
    }
    
    public String toString(final Descriptors.FieldDescriptor field, final Object value) {
        return this.getPrinter().printFieldToString(field, value);
    }
    
    public String toString(final UnknownFieldSet fields) {
        return this.getPrinter().printToString(fields);
    }
    
    public Object lazyToString(final MessageOrBuilder message) {
        return new LazyDebugOutput(message, this);
    }
    
    public Object lazyToString(final UnknownFieldSet fields) {
        return new LazyDebugOutput(fields, this);
    }
    
    private static class LazyDebugOutput
    {
        private final MessageOrBuilder message;
        private final UnknownFieldSet fields;
        private final DebugFormat format;
        
        LazyDebugOutput(final MessageOrBuilder message, final DebugFormat format) {
            this.message = message;
            this.fields = null;
            this.format = format;
        }
        
        LazyDebugOutput(final UnknownFieldSet fields, final DebugFormat format) {
            this.message = null;
            this.fields = fields;
            this.format = format;
        }
        
        @Override
        public String toString() {
            if (this.message != null) {
                return this.format.toString(this.message);
            }
            return this.format.toString(this.fields);
        }
    }
}
