public static <T extends com.google.protobuf.GeneratedMessageV3> ProtobufSchema<T> of( Class<T> pojo, Map<String, String> properties){ return ofGenericClass(pojo, properties); } }
/** * Key Value Schema using passed in schema type, support JSON and AVRO currently. */ public static <K, V> Schema<KeyValue<K, V>> of(Class<K> key, Class<V> value, SchemaType type) { checkArgument(SchemaType.JSON == type || SchemaType.AVRO == type); if (SchemaType.JSON == type) { return new KeyValueSchema<>(JSONSchema.of(key), JSONSchema.of(value)); } else { // AVRO return new KeyValueSchema<>(AvroSchema.of(key), AvroSchema.of(value)); } }
@Override public Byte decode(byte[] bytes) { if (null == bytes) { return null; } validate(bytes); return bytes[0]; }
public static <T> AvroSchema<T> of(Class<T> pojo, Map<String, String> properties) { return new AvroSchema<>(createAvroSchema(pojo), properties); }
@Override public void validate(byte[] message) { ensureSchemaInitialized(); schema.validate(message); }
@Override public void validate(byte[] message) { ensureSchemaInitialized(); schema.validate(message); }
public static <T> JSONSchema<T> of(Class<T> pojo, Map<String, String> properties) { return new JSONSchema<>(pojo, properties); } }
@Override public Long decode(byte[] bytes) { if (null == bytes) { return null; } validate(bytes); long value = 0L; for (byte b : bytes) { value <<= 8; value |= b & 0xFF; } return value; }
@Override public Integer decode(byte[] bytes) { if (null == bytes) { return null; } validate(bytes); int value = 0; for (byte b : bytes) { value <<= 8; value |= b & 0xFF; } return value; }
@Override public Short decode(byte[] bytes) { if (null == bytes) { return null; } validate(bytes); short value = 0; for (byte b : bytes) { value <<= 8; value |= b & 0xFF; } return value; }
public static <T extends com.google.protobuf.GeneratedMessageV3> ProtobufSchema<T> of(Class<T> pojo) { return of(pojo, Collections.emptyMap()); }
@Override public Double decode(byte[] bytes) { if (null == bytes) { return null; } validate(bytes); long value = 0; for (byte b : bytes) { value <<= 8; value |= b & 0xFF; } return Double.longBitsToDouble(value); }
@Override public Boolean decode(byte[] bytes) { if (null == bytes) { return null; } validate(bytes); return bytes[0] != 0; }
@Override public SchemaInfo getSchemaInfo() { ensureSchemaInitialized(); return schema.getSchemaInfo(); } }
@Override public SchemaInfo getSchemaInfo() { ensureSchemaInitialized(); return schema.getSchemaInfo(); }
public static <T> JSONSchema<T> of(Class<T> pojo) { return new JSONSchema<>(pojo, Collections.emptyMap()); }
@Override public byte[] encode(byte[] message) { ensureSchemaInitialized(); if (requireSchemaValidation) { // verify if the message can be decoded by the underlying schema schema.validate(message); } return message; }
@Override public GenericRecord decode(byte[] bytes) { ensureSchemaInitialized(); return schema.decode(bytes); }
@Override public byte[] decode(byte[] bytes) { ensureSchemaInitialized(); if (requireSchemaValidation) { // verify the message can be detected by the underlying schema schema.decode(bytes); } return bytes; }
@Override public byte[] encode(GenericRecord message) { ensureSchemaInitialized(); return schema.encode(message); }