BlinkCodec implements MsgCodec { @Override public void encode(Object group, OutputStream out) throws IOException { encode(group, new OutputStreamSink(out)); } BlinkCodec(Schema schema, Pool<byte[]> bufferPool,
            int maxBinarySize, int maxSequenceLength); @Override void encode(Object group, OutputStream out); @Override void encode(Object group, ByteSink out); @Override Object decode(InputStream in); @Override Object decode(ByteSource in);  }
@Test public void testMultipleDynamics() throws IllegalArgumentException, IOException { Schema schema = new SchemaBuilder().build(DynamicMsgs.class, IntMsg.class); byte[] byteData = new byte[1024]; ByteBuf buffer = new ByteBufferBuf(ByteBuffer.wrap(byteData)); MsgCodec codec = new BlinkCodecFactory(schema).createCodec(); codec.encode(new DynamicMsgs(new IntMsg(42), null, null), buffer); buffer.clear(); codec.encode(new DynamicMsgs(new IntMsg(42), new IntMsg(1), new IntMsg(2)), buffer); }
@Test(expected = IllegalArgumentException.class) public void testFailEncodeBadSymbol() throws IOException { Schema schema = new SchemaBuilder().build(EnumMsg.class); ByteArrayOutputStream bout = new ByteArrayOutputStream(); ArrayList<GroupDef> groups = new ArrayList<>(); for (GroupDef group : schema.getGroups()) { if (group.getName().equals("EnumMsg")) { ArrayList<FieldDef> fields = new ArrayList<>(); for (FieldDef field : group.getFields()) { if (field.getName().equals("aEnum")) { FieldBinding binding = field.getBinding(); field = field.bind( new FieldBinding(binding.getAccessor(), binding.getJavaClass(), binding.getComponentJavaClass(), new BadSymbolMapping())); } fields.add(field); } group = new GroupDef(group.getName(), group.getId(), group.getSuperGroup(), fields, group.getAnnotations(), group.getBinding()); } groups.add(group); } schema = new Schema(groups, schema.getNamedTypes(), schema.getAnnotations(), schema.getBinding()); BlinkCodec codec = new BlinkCodecFactory(schema).createCodec(); codec.encode(new EnumMsg(AEnum.VALUE), bout); }
@Test public void testWriteNonReqWithNonNullReference() throws IOException { Schema schema = new SchemaBuilder().build(SingleFieldEntity.class, IntMsg.class); BlinkCodec codec = new BlinkCodecFactory(schema).createCodec(); ByteArrayOutputStream out = new ByteArrayOutputStream(); SingleFieldEntity entity = new SingleFieldEntity(); entity.optionalIntMessage = new IntMsg(0x37); codec.encode(entity, out); byte[] expected = new byte[]{0x03, 0x09, 0x01, 0x37}; System.err.println(ByteBuffers.toHex(ByteBuffer.wrap(out.toByteArray()))); assertArrayEquals(expected, out.toByteArray()); }
@Test public void testWriteNonReqWithNullReference() throws IOException { Schema schema = new SchemaBuilder().build(SingleFieldEntity.class, IntMsg.class); BlinkCodec codec = new BlinkCodecFactory(schema).createCodec(); ByteArrayOutputStream out = new ByteArrayOutputStream(); SingleFieldEntity entity = new SingleFieldEntity(); codec.encode(entity, out); byte[] expected = new byte[]{0x02, 0x09, (byte)0xc0}; System.err.println(ByteBuffers.toHex(ByteBuffer.wrap(out.toByteArray()))); assertArrayEquals(expected, out.toByteArray()); }