@Override protected Class<?> enumClass(int id) { final RegisteredEnumIO reio = id < enums.size() ? enums.get(id) : null; if (reio == null) { throw new UnknownTypeException("enum id: " + id + " (Outdated registry)"); } return reio.eio.enumClass; }
@Override protected CollectionSchema.MessageFactory getCollectionFactory(Class<?> clazz) { final RegisteredCollectionFactory rf = collectionMapping.get(clazz); if (rf == null) { if (clazz.getName().startsWith("java.util")) return CollectionSchema.MessageFactories.valueOf(clazz.getSimpleName()); throw new UnknownTypeException("collection: " + clazz); } return rf; }
@Override protected Class<?> enumClass(int id) { final RuntimeEnumIO reio = id < enums.size() ? enums.get(id) : null; if (reio == null) throw new UnknownTypeException("Unknown enum id: " + id); return reio.eio.enumClass; }
@Override protected int getEnumId(Class<?> clazz) { final RegisteredEnumIO reio = enumMapping.get(clazz); if (reio == null) throw new UnknownTypeException("enum: " + clazz); return (reio.id << 5) | CID_ENUM; }
@Override @SuppressWarnings("unchecked") protected <T> HasSchema<T> resolvePojoFrom(Input input, int fieldNumber) throws IOException { final int id = input.readUInt32(); final BaseHS<T> wrapper = id < pojos.size() ? (BaseHS<T>) pojos.get(id) : null; if (wrapper == null) throw new UnknownTypeException("pojo id: " + id + " (Outdated registry)"); return wrapper; }
@Override protected CollectionSchema.MessageFactory resolveCollectionFrom(Input input) throws IOException { final int id = input.readUInt32(); final CollectionSchema.MessageFactory factory = id < collections.size() ? collections.get(id) : null; if (factory == null) throw new UnknownTypeException("collection id: " + id + " (Outdated registry)"); return factory; }
@Override protected Class<?> pojoClass(int id) { final BaseHS<?> wrapper = id < pojos.size() ? pojos.get(id) : null; if (wrapper == null) throw new UnknownTypeException("Unknown pojo id: " + id); return wrapper.getSchema().typeClass(); }
@Override protected Class<?> collectionClass(int id) { final RuntimeCollectionFactory factory = id < collections.size() ? collections.get(id) : null; if (factory == null) throw new UnknownTypeException("Unknown collection id: " + id); return factory.typeClass(); }
@Override @SuppressWarnings("unchecked") protected <T> HasSchema<T> transferPojoId(Input input, Output output, int fieldNumber) throws IOException { final int id = input.readUInt32(); final BaseHS<T> wrapper = id < pojos.size() ? (BaseHS<T>) pojos.get(id) : null; if (wrapper == null) throw new UnknownTypeException("unknown pojo id: " + id); output.writeUInt32(fieldNumber, id, false); return wrapper; }
@Override protected Class<?> mapClass(int id) { final RegisteredMapFactory factory = id < maps.size() ? maps.get(id) : null; if (factory == null) { throw new UnknownTypeException("map id: " + id + " (Outdated registry)"); } return factory.typeClass(); }
@Override @SuppressWarnings("unchecked") protected <T> HasDelegate<T> resolveDelegateFrom(Input input) throws IOException { final int id = input.readUInt32(); final RegisteredDelegate<T> rd = id < delegates.size() ? (RegisteredDelegate<T>) delegates.get(id) : null; if (rd == null) throw new UnknownTypeException("delegate id: " + id + " (Outdated registry)"); return rd; }
@Override protected EnumIO<?> resolveEnumFrom(Input input) throws IOException { final int id = input.readUInt32(); final RegisteredEnumIO reio = id < enums.size() ? enums.get(id) : null; if (reio == null) throw new UnknownTypeException("enum id: " + id + " (Outdated registry)"); return reio.eio; }
@Override @SuppressWarnings("unchecked") protected <T> HasSchema<T> resolvePojoFrom(Input input, int fieldNumber) throws IOException { final int id = input.readUInt32(); final BaseHS<T> wrapper = id < pojos.size() ? (BaseHS<T>) pojos.get(id) : null; if (wrapper == null) throw new UnknownTypeException("unknown pojo id: " + id); return wrapper; }
@Override protected MapSchema.MessageFactory resolveMapFrom(Input input) throws IOException { final int id = input.readUInt32(); final RuntimeMapFactory factory = id < maps.size() ? maps.get(id) : null; if (factory == null) throw new UnknownTypeException("Unknown map id: " + id); return factory; }
@Override protected MapSchema.MessageFactory resolveMapFrom(Input input) throws IOException { final int id = input.readUInt32(); final MapSchema.MessageFactory factory = id < maps.size() ? maps.get(id) : null; if (factory == null) throw new UnknownTypeException("map id: " + id + " (Outdated registry)"); return factory; }
@Override protected void writeMapIdTo(Output output, int fieldNumber, Class<?> clazz) throws IOException { final RegisteredMapFactory factory = mapMapping.get(clazz); if (factory == null) throw new UnknownTypeException("map: " + clazz); output.writeUInt32(fieldNumber, factory.id, false); }
@Override protected Class<?> mapClass(int id) { final RuntimeMapFactory factory = id < maps.size() ? maps.get(id) : null; if (factory == null) throw new UnknownTypeException("Unknown map id: " + id); return factory.typeClass(); }
@Override @SuppressWarnings("unchecked") protected <T> Schema<T> writeMessageIdTo(Output output, int fieldNumber, Message<T> message) throws IOException { final BaseHS<T> wrapper = (BaseHS<T>) pojoMapping.get(message.getClass()); if (wrapper == null) throw new UnknownTypeException("pojo: " + message.getClass()); output.writeUInt32(fieldNumber, wrapper.id, false); // TODO allow the wrapper to return an override schema? return message.cachedSchema(); }
@Override @SuppressWarnings("unchecked") protected <T> HasSchema<T> transferPojoId(Input input, Output output, int fieldNumber) throws IOException { final int id = input.readUInt32(); final BaseHS<T> wrapper = (BaseHS<T>) pojos.get(id); if (wrapper == null) throw new UnknownTypeException("pojo id: " + id + " (Outdated registry)"); output.writeUInt32(fieldNumber, id, false); return wrapper; }
@Override @SuppressWarnings("unchecked") protected <T> HasSchema<T> writePojoIdTo(Output output, int fieldNumber, Class<T> clazz) throws IOException { final BaseHS<T> wrapper = (BaseHS<T>) pojoMapping.get(clazz); if (wrapper == null) throw new UnknownTypeException("pojo: " + clazz); output.writeUInt32(fieldNumber, wrapper.id, false); return wrapper; }