bfld = binType.field(s); fieldsCache.put(s, bfld);
/** * Get binary field for the property. * * @param obj Target object. * @return Binary field. */ private BinaryField binaryField(BinaryObject obj) { if (ctx.query().skipFieldLookup()) return null; BinaryField field0 = field; if (field0 == null && !fieldTaken) { BinaryType type = obj instanceof BinaryObjectEx ? ((BinaryObjectEx)obj).rawType() : obj.type(); if (type != null) { field0 = type.field(propName); assert field0 != null; field = field0; } fieldTaken = true; } return field0; }
/** * @throws Exception If failed. */ @Test public void testPrimitiveMarshalling() throws Exception { BinaryMarshaller marsh = createMarshaller(); ThreadLocalRandom rnd = ThreadLocalRandom.current(); TestObject obj = new TestObject(0); BinaryObjectImpl binObj = toBinary(obj, marsh); BinaryFieldEx[] fields = new BinaryFieldEx[] { (BinaryFieldEx)binObj.type().field("bVal"), (BinaryFieldEx)binObj.type().field("cVal"), (BinaryFieldEx)binObj.type().field("sVal"), (BinaryFieldEx)binObj.type().field("iVal"), (BinaryFieldEx)binObj.type().field("lVal"), (BinaryFieldEx)binObj.type().field("fVal"), (BinaryFieldEx)binObj.type().field("dVal") }; ByteBuffer buf = ByteBuffer.allocate(1024 * 1024); for (int i = 0; i < 100; i++) { TestObject to = new TestObject(rnd.nextLong()); BinaryObjectImpl bObj = toBinary(to, marsh); for (BinaryFieldEx field : fields) field.writeField(bObj, buf); buf.flip(); for (BinaryFieldEx field : fields) assertEquals(field.value(bObj), field.readField(buf)); buf.flip(); } }
/** * Get test context. * * @param marsh Binary marshaller. * @param fieldName Field name. * @return Test context. * @throws Exception If failed. */ private TestContext context(BinaryMarshaller marsh, String fieldName) throws Exception { TestObject obj = createObject(); BinaryObjectExImpl portObj = toBinary(marsh, obj); BinaryField field = portObj.type().field(fieldName); return new TestContext(obj, portObj, field); }
/** * @throws Exception If failed. */ @Test public void testDecimalFieldMarshalling() throws Exception { BinaryMarshaller marsh = createMarshaller(); BigDecimal values[] = new BigDecimal[] { BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN, new BigDecimal("-100.5"), BigDecimal.valueOf(Long.MAX_VALUE, 0), BigDecimal.valueOf(Long.MIN_VALUE, 0), BigDecimal.valueOf(Long.MAX_VALUE, 8), BigDecimal.valueOf(Long.MIN_VALUE, 8)}; DecimalValue decVal = new DecimalValue(values[0]); BinaryObjectImpl binObj = toBinary(decVal, marsh); BinaryFieldEx field = (BinaryFieldEx)binObj.type().field("decVal"); ByteBuffer buf = ByteBuffer.allocate(64); for (BigDecimal value : values) { decVal = new DecimalValue(value); binObj = toBinary(decVal, marsh); field.writeField(binObj, buf); buf.flip(); assertEquals(field.value(binObj), field.readField(buf)); buf.clear(); } }
/** * @throws Exception If failed. */ @Test public void testTimeMarshalling() throws Exception { BinaryMarshaller marsh = createMarshaller(); TimeValue obj = new TimeValue(11111L); BinaryObjectImpl binObj = toBinary(obj, marsh); BinaryFieldEx field = (BinaryFieldEx)binObj.type().field("time"); ByteBuffer buf = ByteBuffer.allocate(16); field.writeField(binObj, buf); buf.flip(); assertEquals(field.value(binObj), field.<Time>readField(buf)); }
/** * Get test context with nested test object. * * @param marsh Binary marshaller. * @param fieldName Field name. * @return Test context. * @throws Exception If failed. */ private TestContext nestedContext(BinaryMarshaller marsh, String fieldName) throws Exception { TestObject obj = createObject(); TestOuterObject outObj = new TestOuterObject(obj); BinaryObjectExImpl portOutObj = toBinary(marsh, outObj); BinaryObjectExImpl portObj = portOutObj.field("fInner"); assert portObj != null; BinaryField field = portObj.type().field(fieldName); return new TestContext(obj, portObj, field); }
assertArrayEquals(obj1.valArr, (BigDecimal[])portObj.type().field("valArr").value(portObj)); assertEquals(obj1.val, portObj.type().field("val").value(portObj)); assertArrayEquals(obj2.rawValArr, portObj.<DecimalMarshalAware>deserialize().rawValArr); assertEquals(obj2.val, portObj.type().field("val").value(portObj)); assertArrayEquals(obj2.valArr, (BigDecimal[])portObj.type().field("valArr").value(portObj)); assertEquals(obj2.val, portObj.type().field("val").value(portObj));
/** * Get binary field for the property. * * @param obj Target object. * @return Binary field. */ private BinaryField binaryField(BinaryObject obj) { if (ctx.query().skipFieldLookup()) return null; BinaryField field0 = field; if (field0 == null && !fieldTaken) { BinaryType type = obj instanceof BinaryObjectEx ? ((BinaryObjectEx)obj).rawType() : obj.type(); if (type != null) { field0 = type.field(propName); assert field0 != null; field = field0; } fieldTaken = true; } return field0; }