Package org.msgpack.template

Examples of org.msgpack.template.Template


        return createUnpacker(in).readValue();
    }

    public <T> T read(byte[] b, T v) throws IOException // TODO IOException
        // TODO
        Template tmpl = registry.lookup(v.getClass());
        BufferUnpacker u = createBufferUnpacker(b);
        return (T) tmpl.read(u, v);
    }
View Full Code Here


    public void writeMapEnd() throws IOException {
        writeMapEnd(true);
    }

    public Packer write(Object o) throws IOException {
        Template tmpl = msgpack.lookup(o.getClass());
        tmpl.write(this, o);
        return this;
    }
View Full Code Here

  return lookupImpl(targetType, true, forceBuild, false);
    }

    private synchronized Template lookupImpl(Type targetType,
      final boolean forceLoad, final boolean forceBuild, final boolean fallbackDefault) {
  Template tmpl;

  if (targetType instanceof ParameterizedType) {
      ParameterizedType pType = (ParameterizedType) targetType;
      // ParameterizedType is not a Class<?>?
      tmpl = lookupGenericImpl(pType);
View Full Code Here

    }

    public synchronized Template lookupGeneric(final Type targetType) {
  if (targetType instanceof ParameterizedType) {
      ParameterizedType parameterizedType = (ParameterizedType)targetType;
      Template tmpl = lookupGenericImpl(parameterizedType);
      if (tmpl != null) {
    return tmpl;
      }
      return new DefaultTemplate(this, (Class<?>) parameterizedType.getRawType(), parameterizedType);
  } else {
View Full Code Here

      } else if (baseClass == float.class) {
    return FloatArrayTemplate.getInstance();
      } else if (baseClass == double.class) {
    return DoubleArrayTemplate.getInstance();
      } else {
    Template baseTemplate = registry.lookup(genericBaseType);
    return new ObjectArrayTemplate(baseClass, baseTemplate);
      }
  } else if (dim == 2) {
      Class componentClass = Array.newInstance(baseClass, 0).getClass();
      Template componentTemplate = toTemplate(arrayType, genericBaseType, baseClass, dim - 1);
      return new ReflectionMultidimentionalArrayTemplate(componentClass, componentTemplate);
  } else {
      ReflectionMultidimentionalArrayTemplate componentTemplate =
    (ReflectionMultidimentionalArrayTemplate) toTemplate(arrayType, genericBaseType, baseClass, dim - 1);
      Class componentClass = Array.newInstance(componentTemplate.getComponentClass(), 0).getClass();
      return new ReflectionMultidimentionalArrayTemplate(componentClass, componentTemplate);
  }
    }
View Full Code Here

      FieldEntry e = entries[i];
      Class<?> type = e.getType();
      if (type.isPrimitive()) {
    tmpls[i] = new ReflectionBeansFieldTemplate(e);
      } else {
    Template tmpl = registry.lookup(e.getGenericType(), true);
    tmpls[i] = new FieldTemplateImpl(e, tmpl);
      }
  }
  return tmpls;
    }
View Full Code Here

  ReflectionFieldTemplate[] templates = new ReflectionFieldTemplate[entries.length];
  for (int i = 0; i < entries.length; i++) {
      FieldEntry entry = entries[i];
      Class<?> t = entry.getType();
      Template template = registry.lookup(entry.getGenericType(), true);
      templates[i] = new FieldTemplateImpl(entry, template);
  }
  return templates;
    }
View Full Code Here

    public String getName() {
        return "Msgpack";
    }

    public void serialize(Object data, OutputStream outputStream) throws Exception {
        Template template = getTemplate(data.getClass());

        messagePack.write(outputStream, data, template);
    }
View Full Code Here

        messagePack.write(outputStream, data, template);
    }

    public Object deserialize(Class clazz, InputStream inputStream) throws Exception {
        Template template = getTemplate(clazz);

        return messagePack.read(inputStream, template);
    }
View Full Code Here

        return messagePack.read(inputStream, template);
    }

    private Template getTemplate(Class clazz) {
        Template template = templates.get(clazz);
        if (template == null) {
            if (clazz.isArray()) {
                template = new ObjectArrayTemplate(clazz.getComponentType(), messagePack.lookup(clazz.getComponentType()));
            } else {
                template = messagePack.lookup(clazz);
View Full Code Here

TOP

Related Classes of org.msgpack.template.Template

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.