@Override protected int getId(Class<?> clazz) { if (Message.class.isAssignableFrom(clazz)) { final BaseHS<?> wrapper = pojoMapping.get(clazz); if (wrapper == null) throw new UnknownTypeException("pojo: " + clazz); return (wrapper.id << 5) | CID_POJO; } if (Map.class.isAssignableFrom(clazz)) return EnumMap.class.isAssignableFrom(clazz) ? CID_ENUM_MAP : mapId(clazz); if (Collection.class.isAssignableFrom(clazz)) return EnumSet.class.isAssignableFrom(clazz) ? CID_ENUM_SET : collectionId(clazz); final BaseHS<?> wrapper = pojoMapping.get(clazz); if (wrapper == null) throw new UnknownTypeException("pojo: " + clazz); return (wrapper.id << 5) | CID_POJO; }
@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> transferDelegateId(Input input, Output output, int fieldNumber) throws IOException { final String className = input.readString(); final HasDelegate<T> hd = (HasDelegate<T>) delegateMapping .get(className); if (hd == null) throw new UnknownTypeException("delegate: " + className + " (Outdated registry)"); output.writeString(fieldNumber, className, false); return hd; }
@Override @SuppressWarnings("unchecked") protected <T> HasDelegate<T> transferDelegateId(Input input, Output output, int fieldNumber) throws IOException { final String className = input.readString(); final HasDelegate<T> hd = (HasDelegate<T>) delegateMapping .get(className); if (hd == null) throw new UnknownTypeException("delegate: " + className + " (Outdated registry)"); output.writeString(fieldNumber, className, false); return hd; }
@Override @SuppressWarnings("unchecked") protected <T> HasDelegate<T> resolveDelegateFrom(Input input) throws IOException { final String className = input.readString(); final HasDelegate<T> hd = (HasDelegate<T>) delegateMapping .get(className); if (hd == null) throw new UnknownTypeException("delegate: " + className + " (Outdated registry)"); return hd; }
@Override @SuppressWarnings("unchecked") protected <T> HasDelegate<T> resolveDelegateFrom(Input input) throws IOException { final String className = input.readString(); final HasDelegate<T> hd = (HasDelegate<T>) delegateMapping .get(className); if (hd == null) throw new UnknownTypeException("delegate: " + className + " (Outdated registry)"); return hd; }
@Override @SuppressWarnings("unchecked") protected <T> HasDelegate<T> transferDelegateId(Input input, Output output, int fieldNumber) 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)"); output.writeUInt32(fieldNumber, id, false); return rd; }
@Override @SuppressWarnings("unchecked") protected <T> HasDelegate<T> transferDelegateId(Input input, Output output, int fieldNumber) 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)"); output.writeUInt32(fieldNumber, id, false); return rd; }
private int mapId(Class<?> clazz) { final RegisteredMapFactory factory = mapMapping.get(clazz); if (factory == null) throw new UnknownTypeException("map: " + clazz); return (factory.id << 5) | CID_MAP; }
@Override protected Class<?> pojoClass(int id) { final BaseHS<?> wrapper = id < pojos.size() ? pojos.get(id) : null; if (wrapper == null) { throw new UnknownTypeException("pojo id: " + id + " (Outdated registry)"); } return wrapper.getSchema().typeClass(); }
@Override protected Class<?> collectionClass(int id) { final RegisteredCollectionFactory factory = id < collections.size() ? collections.get(id) : null; if (factory == null) { throw new UnknownTypeException("collection id: " + id + " (Outdated registry)"); } return factory.typeClass(); }
@Override protected void writeEnumIdTo(Output output, int fieldNumber, Class<?> clazz) throws IOException { final RegisteredEnumIO reio = enumMapping.get(clazz); if (reio == null) throw new UnknownTypeException("enum: " + clazz); output.writeUInt32(fieldNumber, reio.id, false); }
@Override protected EnumIO<? extends Enum<?>> getEnumIO(Class<?> enumClass) { final RegisteredEnumIO reio = enumMapping.get(enumClass); if (reio == null) throw new UnknownTypeException("enum: " + enumClass); return reio.eio; }
@Override @SuppressWarnings("unchecked") public <T> HasSchema<T> getSchemaWrapper(Class<T> typeClass, boolean create) { final BaseHS<T> wrapper = (BaseHS<T>) pojoMapping.get(typeClass); if (wrapper == null && create) throw new UnknownTypeException("pojo: " + typeClass); return wrapper; }
@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 RuntimeEnumIO reio = id < enums.size() ? enums.get(id) : null; if (reio == null) throw new UnknownTypeException("Unknown enum id: " + id); return reio.eio; }
@Override protected CollectionSchema.MessageFactory resolveCollectionFrom(Input input) throws IOException { final int id = input.readUInt32(); final RuntimeCollectionFactory factory = id < collections.size() ? collections.get(id) : null; if (factory == null) throw new UnknownTypeException("Unknown collection id: " + id); return factory; }
private int collectionId(Class<?> clazz) { final RegisteredCollectionFactory factory = collectionMapping.get(clazz); if (factory == null) throw new UnknownTypeException("collection: " + clazz); return (factory.id << 5) | CID_COLLECTION; }
@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; }