Added some helpful utils, license

This commit is contained in:
Christian Basler 2017-01-25 22:41:57 +01:00
parent 428ffb2a6d
commit 43c7267e14
4 changed files with 40 additions and 22 deletions

View File

@ -59,9 +59,9 @@ uploadArchives {
url 'https://dissem.ch/msgpack' url 'https://dissem.ch/msgpack'
scm { scm {
connection 'scm:git:https://github.com/Dissem/msgpack.git' connection 'scm:git:https://git.dissem.ch/chris/MessagePack.git'
developerConnection 'scm:git:git@github.com:Dissem/msgpack.git' developerConnection 'scm:git:git@git.dissem.ch:chris/MessagePack.git'
url 'https://github.com/Dissem/msgpack.git' url 'https://git.dissem.ch/chris/MessagePack.git'
} }
licenses { licenses {

View File

@ -29,18 +29,23 @@ import java.util.List;
public class Reader { public class Reader {
private List<MPType.Unpacker<?>> unpackers = new LinkedList<>(); private List<MPType.Unpacker<?>> unpackers = new LinkedList<>();
public Reader() { private static final Reader instance = new Reader();
private Reader() {
unpackers.add(new MPNil.Unpacker()); unpackers.add(new MPNil.Unpacker());
unpackers.add(new MPBoolean.Unpacker()); unpackers.add(new MPBoolean.Unpacker());
unpackers.add(new MPInteger.Unpacker()); unpackers.add(new MPInteger.Unpacker());
unpackers.add(new MPFloat.Unpacker()); unpackers.add(new MPFloat.Unpacker());
unpackers.add(new MPDouble.Unpacker());
unpackers.add(new MPString.Unpacker()); unpackers.add(new MPString.Unpacker());
unpackers.add(new MPBinary.Unpacker()); unpackers.add(new MPBinary.Unpacker());
unpackers.add(new MPMap.Unpacker(this)); unpackers.add(new MPMap.Unpacker(this));
unpackers.add(new MPArray.Unpacker(this)); unpackers.add(new MPArray.Unpacker(this));
} }
public static Reader getInstance() {
return instance;
}
/** /**
* Register your own extensions * Register your own extensions
*/ */

View File

@ -1,19 +1,3 @@
/*
* Copyright 2017 Christian Basler
*
* Licensed 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 ch.dissem.msgpack.types; package ch.dissem.msgpack.types;
import ch.dissem.msgpack.Reader; import ch.dissem.msgpack.Reader;

View File

@ -20,8 +20,9 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
class Utils { public class Utils {
private static final char[] BASE64_CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray(); private static final char[] BASE64_CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray();
private static final MPNil NIL = new MPNil();
/** /**
* Returns a {@link ByteBuffer} containing the next <code>count</code> bytes from the {@link InputStream}. * Returns a {@link ByteBuffer} containing the next <code>count</code> bytes from the {@link InputStream}.
@ -83,4 +84,32 @@ class Utils {
return result.toString(); return result.toString();
} }
public static MPString mp(String value) {
return new MPString(value);
}
public static MPBoolean mp(boolean value) {
return new MPBoolean(value);
}
public static MPFloat mp(double value) {
return new MPFloat(value);
}
public static MPFloat mp(float value) {
return new MPFloat(value);
}
public static MPInteger mp(int value) {
return new MPInteger(value);
}
public static MPBinary mp(byte... data) {
return new MPBinary(data);
}
public static MPNil nil() {
return NIL;
}
} }