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

package org.bson;

import org.bson.codecs.configuration.CodecRegistries;
import org.bson.codecs.configuration.CodecProvider;
import org.bson.io.BsonInputMark;
import org.bson.codecs.DecoderContext;
import org.bson.codecs.BsonValueCodecProvider;
import org.bson.codecs.configuration.CodecRegistry;

final class RawBsonValueHelper
{
    private static final CodecRegistry REGISTRY;
    
    static BsonValue decode(final byte[] bytes, final BsonBinaryReader bsonReader) {
        if (bsonReader.getCurrentBsonType() != BsonType.DOCUMENT && bsonReader.getCurrentBsonType() != BsonType.ARRAY) {
            return RawBsonValueHelper.REGISTRY.get(BsonValueCodecProvider.getClassForBsonType(bsonReader.getCurrentBsonType())).decode(bsonReader, DecoderContext.builder().build());
        }
        final int position = bsonReader.getBsonInput().getPosition();
        final BsonInputMark mark = bsonReader.getBsonInput().getMark(4);
        final int size = bsonReader.getBsonInput().readInt32();
        mark.reset();
        bsonReader.skipValue();
        if (bsonReader.getCurrentBsonType() == BsonType.DOCUMENT) {
            return new RawBsonDocument(bytes, position, size);
        }
        return new RawBsonArray(bytes, position, size);
    }
    
    private RawBsonValueHelper() {
    }
    
    static {
        REGISTRY = CodecRegistries.fromProviders(new BsonValueCodecProvider());
    }
}
