Skip to content

Commit

Permalink
Simplestringserde (apache#19)
Browse files Browse the repository at this point in the history
* Create pulsar-functions module (#1)

* Create pulsar-functions module

* rename `sdk` package to `api`

* Added the first cut of the Java interface for Pulsar functions (#2)

* Added a simple String based serde
  • Loading branch information
srkukarni authored and sijie committed Mar 4, 2018
1 parent 52c9c24 commit 85e1882
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pulsar-functions/run-examples.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CLASSPATH=`pwd`/api-examples/target/pulsar-functions-api-examples.jar bin/pulsar-functions functions run --function-config conf/example.yml --sink-topic persistent://sample/standalone/ns1/test_result --source-topic persistent://sample/standalone/ns1/test_src --function-classpath `pwd`/api-examples/target/pulsar-functions-api-examples.jar
CLASSPATH=`pwd`/api-examples/target/pulsar-functions-api-examples.jar bin/pulsar-functions functions run --function-config conf/example.yml --sink-topic persistent://sample/standalone/ns1/test_result --source-topic persistent://sample/standalone/ns1/test_src --serde-classname org.apache.pulsar.functions.runtime.container.SimpleStringSerDe --function-classpath `pwd`/api-examples/target/pulsar-functions-api-examples.jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.pulsar.functions.runtime.container;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

/**
* A simple Serde that treats the bytes as Java String
*/
public class SimpleStringSerDe implements SerDe {
private static final Logger log = LoggerFactory.getLogger(SimpleStringSerDe.class);

public SimpleStringSerDe() { }

@Override
public byte[] serialize(Object resultValue) {
String string = (String) resultValue;
return string.getBytes();
}

@Override
public Object deserialize(byte[] data) {
return new String(data);
}
}

0 comments on commit 85e1882

Please sign in to comment.