Java Code Examples for co.nstant.in.cbor.CborEncoder#encode()

The following examples show how to use co.nstant.in.cbor.CborEncoder#encode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Example49Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(VALUE);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 2
Source File: Example46Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(VALUE);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 3
Source File: Example64Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(new CborBuilder().addArray().add(1).add(2).add(3).end().build());
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 4
Source File: Example14Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteArrayOutputStream);
    encoder.encode(new NegativeInteger(new BigInteger("-18446744073709551617")));
    Assert.assertArrayEquals(new byte[] { (byte) 0xc3, 0x49, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
        byteArrayOutputStream.toByteArray());
}
 
Example 5
Source File: Example44Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(SimpleValue.UNDEFINED);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 6
Source File: Example71Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(VALUE);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 7
Source File: AbstractStringTest.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(new UnicodeString(value));
    Assert.assertArrayEquals(encodedValue, byteOutputStream.toByteArray());
}
 
Example 8
Source File: CborDecoderTest.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test(expected = CborException.class)
public void shouldThrowOnRationalNumberDecode3() throws CborException {
    List<DataItem> items = new CborBuilder().addTag(30).addArray().add(true).add(true).end().build();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(baos);
    encoder.encode(items);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    CborDecoder decoder = new CborDecoder(bais);
    decoder.decode();
}
 
Example 9
Source File: ByteStringDecoderTest.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDecodeByteString1M() throws CborException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(baos);
    encoder.encode(new CborBuilder().add(new byte[1024 * 1024]).build());
    byte[] encodedBytes = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(encodedBytes);
    CborDecoder decoder = new CborDecoder(bais);
    List<DataItem> dataItems = decoder.decode();
    assertNotNull(dataItems);
    assertEquals(1, dataItems.size());
}
 
Example 10
Source File: Example80Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(VALUE);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 11
Source File: Example77Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(VALUE);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 12
Source File: Example48Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(VALUE);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 13
Source File: LanguageTaggedStringDecoderTest.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test(expected = CborException.class)
public void testExceptionOnNot2ElementArray() throws CborException {
    List<DataItem> items = new CborBuilder().addTag(38).addArray().add(true).end().build();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(baos);
    encoder.encode(items);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    CborDecoder decoder = new CborDecoder(bais);
    decoder.decode();
}
 
Example 14
Source File: Example43Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(SimpleValue.NULL);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 15
Source File: AbstractHalfPrecisionFloatTest.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(new HalfPrecisionFloat(value));
    Assert.assertArrayEquals(encodedValue, byteOutputStream.toByteArray());
}
 
Example 16
Source File: Example41Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(SimpleValue.FALSE);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 17
Source File: Example78Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(VALUE);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 18
Source File: Example75Test.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(VALUE);
    Assert.assertArrayEquals(ENCODED_VALUE, byteOutputStream.toByteArray());
}
 
Example 19
Source File: AbstractDoublePrecisionFloatTest.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    List<DataItem> dataItems = new CborBuilder().add(value).build();
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(dataItems.get(0));
    Assert.assertArrayEquals(encodedValue, byteOutputStream.toByteArray());
}
 
Example 20
Source File: AbstractByteStringTest.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    CborEncoder encoder = new CborEncoder(byteOutputStream);
    encoder.encode(new ByteString(value));
    Assert.assertArrayEquals(encodedValue, byteOutputStream.toByteArray());
}