(node) -> addTypeWithNameCheck(typeByNameMap, new SetType(node), node));
private void add(final SetType type, final int offset, final Field field) { final PrimitiveType encodingType = type.encodingType(); final Encoding encoding = new Encoding.Builder() .semanticType(semanticTypeOf(type, field)) .primitiveType(encodingType) .build(); final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_SET) .name(type.name()) .referencedName(type.referencedName()) .size(encodingType.size()) .offset(offset) .version(type.sinceVersion()) .deprecated(type.deprecated()) .description(type.description()) .encoding(encoding); if (null != field) { builder.version(Math.max(field.sinceVersion(), type.sinceVersion())); } tokenList.add(builder.build()); for (final SetType.Choice choice : type.choices()) { add(choice, encodingType); } builder.signal(Signal.END_SET); tokenList.add(builder.build()); }
@Test public void shouldHandleBinarySetType() throws Exception { final String testXmlString = "<types>" + "<set name=\"biOp\" encodingType=\"uint8\">" + " <choice name=\"Bit0\" description=\"Bit 0\">0</choice>" + " <choice name=\"Bit1\" description=\"Bit 1\">1</choice>" + "</set>" + "</types>"; final Map<String, Type> map = parseTestXmlWithMap("/types/set", testXmlString); final SetType e = (SetType)map.get("biOp"); assertThat(e.name(), is("biOp")); assertThat(e.encodingType(), is(PrimitiveType.UINT8)); assertThat(e.choices().size(), is(2)); assertThat(e.getChoice("Bit1").primitiveValue(), is(PrimitiveValue.parse("1", PrimitiveType.UINT8))); assertThat(e.getChoice("Bit0").primitiveValue(), is(PrimitiveValue.parse("0", PrimitiveType.UINT8))); }
final SetType e = (SetType)map.get("listed"); assertThat(e.encodingType(), is(PrimitiveType.UINT8)); for (final SetType.Choice choice : e.choices())
private void add(final SetType type, final int offset, final Field field) { final PrimitiveType encodingType = type.encodingType(); final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_SET) .name(type.name()) .size(encodingType.size()) .offset(offset) .encoding(new Encoding.Builder() .semanticType(semanticTypeOf(type, field)) .primitiveType(encodingType) .build()); if (field != null) { builder.version(field.sinceVersion()); } tokenList.add(builder.build()); for (final SetType.Choice choice : type.choices()) { add(choice, encodingType, field); } builder.signal(Signal.END_SET); tokenList.add(builder.build()); }
@Test public void shouldHandleEncodingTypesWithNamedTypes() throws Exception { final MessageSchema schema = parse(TestUtil.getLocalResource( "encoding-types-schema.xml"), ParserOptions.DEFAULT); final List<Field> fields = schema.getMessage(1).fields(); assertNotNull(fields); SetType type = (SetType)fields.get(3).type(); assertThat(type.encodingType(), is(PrimitiveType.UINT8)); type = (SetType)fields.get(4).type(); assertThat(type.encodingType(), is(PrimitiveType.UINT16)); type = (SetType)fields.get(5).type(); assertThat(type.encodingType(), is(PrimitiveType.UINT32)); type = (SetType)fields.get(6).type(); assertThat(type.encodingType(), is(PrimitiveType.UINT64)); }
assertThat(setType.name(), is("setOne")); assertThat(nestedCompositeType.name(), is("inner"));
private void add(final SetType type, final int offset, final Field field) { final PrimitiveType encodingType = type.encodingType(); final Encoding encoding = new Encoding.Builder() .semanticType(semanticTypeOf(type, field)) .primitiveType(encodingType) .build(); final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_SET) .name(type.name()) .referencedName(type.referencedName()) .size(encodingType.size()) .offset(offset) .version(type.sinceVersion()) .deprecated(type.deprecated()) .description(type.description()) .encoding(encoding); if (null != field) { builder.version(Math.max(field.sinceVersion(), type.sinceVersion())); } tokenList.add(builder.build()); for (final SetType.Choice choice : type.choices()) { add(choice, encodingType); } builder.signal(Signal.END_SET); tokenList.add(builder.build()); }
type = addType(subTypeNode, subTypeName, new SetType(subTypeNode, givenName, referencedName)); break;
private void add(final SetType type, final int offset, final Field field) { final PrimitiveType encodingType = type.encodingType(); final Encoding encoding = new Encoding.Builder() .semanticType(semanticTypeOf(type, field)) .primitiveType(encodingType) .build(); final Token.Builder builder = new Token.Builder() .signal(Signal.BEGIN_SET) .name(type.name()) .referencedName(type.referencedName()) .size(encodingType.size()) .offset(offset) .version(type.sinceVersion()) .deprecated(type.deprecated()) .description(type.description()) .encoding(encoding); if (null != field) { builder.version(Math.max(field.sinceVersion(), type.sinceVersion())); } tokenList.add(builder.build()); for (final SetType.Choice choice : type.choices()) { add(choice, encodingType); } builder.signal(Signal.END_SET); tokenList.add(builder.build()); }
private static Map<String, Type> parseTestXmlWithMap(final String xPathExpr, final String xml) throws ParserConfigurationException, XPathExpressionException, IOException, SAXException { final Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new ByteArrayInputStream(xml.getBytes())); final XPath xPath = XPathFactory.newInstance().newXPath(); final NodeList list = (NodeList)xPath.compile(xPathExpr).evaluate(document, XPathConstants.NODESET); final Map<String, Type> map = new HashMap<>(); final ParserOptions options = ParserOptions.builder() .stopOnError(true) .suppressOutput(true) .warningsFatal(true) .build(); document.setUserData(XmlSchemaParser.ERROR_HANDLER_KEY, new ErrorHandler(options), null); for (int i = 0, size = list.getLength(); i < size; i++) { final Type t = new SetType(list.item(i)); map.put(t.name(), t); } return map; } }
type = new SetType(list.item(i));
public void execute(final Node node) throws XPathExpressionException { addTypeWithNameCheck(typeByNameMap, new SetType(node), node); } });
(node) -> addTypeWithNameCheck(typeByNameMap, new SetType(node), node));
(node) -> addTypeWithNameCheck(typeByNameMap, new SetType(node), node));
type = addType(subTypeNode, subTypeName, new SetType(subTypeNode, givenName, referencedName)); break;
type = addType(subTypeNode, subTypeName, new SetType(subTypeNode, givenName, referencedName)); break;