Search in sources :

Example 11 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerReal method encodeAndSave.

public void encodeAndSave(int encodingSizeGuess) throws IOException {
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(encodingSizeGuess);
    encode(os, false);
    code = os.getArray();
}
Also used : ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)

Example 12 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerIntegerTest method encodeDecodeLargeLongs.

@Test
public void encodeDecodeLargeLongs() throws IOException {
    ReverseByteArrayOutputStream os = new ReverseByteArrayOutputStream(50);
    BerInteger myInt = new BerInteger(BigInteger.valueOf(20093243433l));
    myInt.encode(os, true);
    ByteArrayInputStream berInputStream = new ByteArrayInputStream(os.getArray());
    BerInteger myInt2 = new BerInteger();
    myInt2.decode(berInputStream, true);
    Assert.assertEquals(20093243433l, myInt2.value.longValue());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 13 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerIntegerTest method encodeDecodeLargeNegativeLongs.

@Test
public void encodeDecodeLargeNegativeLongs() throws IOException {
    ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
    BerInteger myInt = new BerInteger(BigInteger.valueOf(-20093243433l));
    myInt.encode(berBAOStream, true);
    ByteArrayInputStream berInputStream = new ByteArrayInputStream(berBAOStream.getArray());
    BerInteger myInt2 = new BerInteger();
    myInt2.decode(berInputStream, true);
    Assert.assertEquals(-20093243433l, myInt2.value.longValue());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 14 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerIntegerTest method implicitEncoding4.

@Test
public void implicitEncoding4() throws IOException {
    ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
    IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(127));
    int length = testInteger.encode(berBAOStream, false);
    Assert.assertEquals(2, length);
    byte[] expectedBytes = new byte[] { 0x01, 0x7f };
    Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray());
}
Also used : ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Example 15 with ReverseByteArrayOutputStream

use of org.openmuc.jasn1.ber.ReverseByteArrayOutputStream in project jasn1 by openmuc.

the class BerIntegerTest method implicitEncoding5.

@Test
public void implicitEncoding5() throws IOException {
    ReverseByteArrayOutputStream berBAOStream = new ReverseByteArrayOutputStream(50);
    IntegerUnivPrim testInteger = new IntegerUnivPrim(BigInteger.valueOf(128));
    int length = testInteger.encode(berBAOStream, false);
    Assert.assertEquals(3, length);
    byte[] expectedBytes = new byte[] { 0x02, 0x00, (byte) 0x80 };
    Assert.assertArrayEquals(expectedBytes, berBAOStream.getArray());
}
Also used : ReverseByteArrayOutputStream(org.openmuc.jasn1.ber.ReverseByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ReverseByteArrayOutputStream (org.openmuc.jasn1.ber.ReverseByteArrayOutputStream)44 Test (org.junit.Test)38 ByteArrayInputStream (java.io.ByteArrayInputStream)25 BerInteger (org.openmuc.jasn1.ber.types.BerInteger)11 BerOctetString (org.openmuc.jasn1.ber.types.BerOctetString)4 BerUTF8String (org.openmuc.jasn1.ber.types.string.BerUTF8String)4 ProfileElement (org.openmuc.jasn1.compiler.pedefinitions.ProfileElement)4 BerBoolean (org.openmuc.jasn1.ber.types.BerBoolean)3 BerNull (org.openmuc.jasn1.ber.types.BerNull)3 BerVisibleString (org.openmuc.jasn1.ber.types.string.BerVisibleString)3 ImplicitlyRetaggedTaggedChoice (org.openmuc.jasn1.compiler.tagging_test.ImplicitlyRetaggedTaggedChoice)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 BerAny (org.openmuc.jasn1.ber.types.BerAny)2 PEHeader (org.openmuc.jasn1.compiler.pedefinitions.PEHeader)2 UInt15 (org.openmuc.jasn1.compiler.pedefinitions.UInt15)2 RetaggedUntaggedChoice (org.openmuc.jasn1.compiler.tagging_test.RetaggedUntaggedChoice)2 ChildInformation (org.openmuc.jasn1.compiler.x690_ber_example.ChildInformation)2 Date (org.openmuc.jasn1.compiler.x690_ber_example.Date)2 EmployeeNumber (org.openmuc.jasn1.compiler.x690_ber_example.EmployeeNumber)2