Package com.couchbase.client.java.document

Examples of com.couchbase.client.java.document.JsonDoubleDocument


        converter = new JsonDoubleTranscoder();
    }

    @Test
    public void shouldEncodeDouble() {
        JsonDoubleDocument document = JsonDoubleDocument.create("id", Double.MAX_VALUE);
        Tuple2<ByteBuf, Integer> encoded = converter.encode(document);

        assertEquals("1.7976931348623157E308", encoded.value1().toString(CharsetUtil.UTF_8));
        assertEquals(TranscoderUtils.JSON_COMPAT_FLAGS, (long) encoded.value2());
    }
View Full Code Here


    }

    @Test
    public void shouldDecodeCommonFlagsDouble() {
        ByteBuf content = Unpooled.copiedBuffer("1.7976931348623157E308", CharsetUtil.UTF_8);
        JsonDoubleDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMMON_FLAGS,
            ResponseStatus.SUCCESS);

        assertEquals(Double.MAX_VALUE, decoded.content(), 0);
    }
View Full Code Here

    @Test
    public void shouldDecodeLegacyDouble() {
        byte[] bytes = LegacyTranscoder.encodeNum(Double.doubleToRawLongBits(Double.MAX_VALUE), 8);
        ByteBuf content = Unpooled.buffer().writeBytes(bytes);
        JsonDoubleDocument decoded = converter.decode("id", content, 0, 0, 7 << 8,
            ResponseStatus.SUCCESS);

        assertEquals(Double.MAX_VALUE, decoded.content(), 0);
    }
View Full Code Here

    @Test
    public void shouldDecodeLegacyFloat() {
        byte[] bytes = LegacyTranscoder.encodeNum(Float.floatToRawIntBits(Float.MAX_VALUE), 4);
        ByteBuf content = Unpooled.buffer().writeBytes(bytes);
        JsonDoubleDocument decoded = converter.decode("id", content, 0, 0, 6 << 8,
            ResponseStatus.SUCCESS);

        assertEquals(Float.MAX_VALUE, decoded.content(), 0);
    }
View Full Code Here

    }

    @Test
    public void shouldReleaseBufferWhenDecoded() {
        ByteBuf content = Unpooled.copiedBuffer("1.7976931348623157E308", CharsetUtil.UTF_8);
        JsonDoubleDocument decoded = converter.decode("id", content, 0, 0, TranscoderUtils.JSON_COMMON_FLAGS,
            ResponseStatus.SUCCESS);
        assertEquals(0, content.refCnt());
    }
View Full Code Here

TOP

Related Classes of com.couchbase.client.java.document.JsonDoubleDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.