static void read(InputBuffer in, MetaData<?> metaData) throws IOException { int size = in.readInt(); for (int i = 0; i < size; i++) metaData.put(in.readString(), in.readBytes()); }
public <T extends Comparable> T readValue(ValueType type) throws IOException { switch (type) { case NULL: return (T)null; case BOOLEAN: return (T)Boolean.valueOf(readBoolean()); case INT: return (T)Integer.valueOf(readInt()); case LONG: return (T)Long.valueOf(readLong()); case FIXED32: return (T)Integer.valueOf(readFixed32()); case FIXED64: return (T)Long.valueOf(readFixed64()); case FLOAT: return (T)Float.valueOf(readFloat()); case DOUBLE: return (T)Double.valueOf(readDouble()); case STRING: return (T)readString(); case BYTES: return (T)readBytes(null); default: throw new TrevniRuntimeException("Unknown value type: "+type); } }
@Test public void testString() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeString(TestUtil.randomString(random)); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(TestUtil.randomString(random), in.readString()); } @Test public void testSkipNull() throws Exception {
static void read(InputBuffer in, MetaData<?> metaData) throws IOException { int size = in.readInt(); for (int i = 0; i < size; i++) metaData.put(in.readString(), in.readBytes()); }
public <T extends Comparable> T readValue(ValueType type) throws IOException { switch (type) { case NULL: return (T)null; case INT: return (T)Integer.valueOf(readInt()); case LONG: return (T)Long.valueOf(readLong()); case FIXED32: return (T)Integer.valueOf(readFixed32()); case FIXED64: return (T)Long.valueOf(readFixed64()); case FLOAT: return (T)Float.valueOf(readFloat()); case DOUBLE: return (T)Double.valueOf(readDouble()); case STRING: return (T)readString(); case BYTES: return (T)readBytes(null); default: throw new TrevniRuntimeException("Unknown value type: "+type); } }
@Test public void testString() throws Exception { Random random = TestUtil.createRandom(); OutputBuffer out = new OutputBuffer(); for (int i = 0; i < COUNT; i++) out.writeString(TestUtil.randomString(random)); InputBuffer in = new InputBuffer(new InputBytes(out.toByteArray())); random = TestUtil.createRandom(); for (int i = 0; i < COUNT; i++) Assert.assertEquals(TestUtil.randomString(random), in.readString()); } @Test public void testSkipNull() throws Exception {