From 43c7267e14416a8fc50729245ba7bf391799c234 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Wed, 25 Jan 2017 22:41:57 +0100 Subject: [PATCH] Added some helpful utils, license --- build.gradle | 6 ++-- src/main/java/ch/dissem/msgpack/Reader.java | 9 ++++-- .../java/ch/dissem/msgpack/types/MPMap.java | 16 ---------- .../java/ch/dissem/msgpack/types/Utils.java | 31 ++++++++++++++++++- 4 files changed, 40 insertions(+), 22 deletions(-) diff --git a/build.gradle b/build.gradle index 903abe3..509edc2 100644 --- a/build.gradle +++ b/build.gradle @@ -59,9 +59,9 @@ uploadArchives { url 'https://dissem.ch/msgpack' scm { - connection 'scm:git:https://github.com/Dissem/msgpack.git' - developerConnection 'scm:git:git@github.com:Dissem/msgpack.git' - url 'https://github.com/Dissem/msgpack.git' + connection 'scm:git:https://git.dissem.ch/chris/MessagePack.git' + developerConnection 'scm:git:git@git.dissem.ch:chris/MessagePack.git' + url 'https://git.dissem.ch/chris/MessagePack.git' } licenses { diff --git a/src/main/java/ch/dissem/msgpack/Reader.java b/src/main/java/ch/dissem/msgpack/Reader.java index b3a8e5c..9b4e5ee 100644 --- a/src/main/java/ch/dissem/msgpack/Reader.java +++ b/src/main/java/ch/dissem/msgpack/Reader.java @@ -29,18 +29,23 @@ import java.util.List; public class Reader { private List> unpackers = new LinkedList<>(); - public Reader() { + private static final Reader instance = new Reader(); + + private Reader() { unpackers.add(new MPNil.Unpacker()); unpackers.add(new MPBoolean.Unpacker()); unpackers.add(new MPInteger.Unpacker()); unpackers.add(new MPFloat.Unpacker()); - unpackers.add(new MPDouble.Unpacker()); unpackers.add(new MPString.Unpacker()); unpackers.add(new MPBinary.Unpacker()); unpackers.add(new MPMap.Unpacker(this)); unpackers.add(new MPArray.Unpacker(this)); } + public static Reader getInstance() { + return instance; + } + /** * Register your own extensions */ diff --git a/src/main/java/ch/dissem/msgpack/types/MPMap.java b/src/main/java/ch/dissem/msgpack/types/MPMap.java index a286b2c..f8e8d3d 100644 --- a/src/main/java/ch/dissem/msgpack/types/MPMap.java +++ b/src/main/java/ch/dissem/msgpack/types/MPMap.java @@ -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; import ch.dissem.msgpack.Reader; diff --git a/src/main/java/ch/dissem/msgpack/types/Utils.java b/src/main/java/ch/dissem/msgpack/types/Utils.java index 3531455..62f68f7 100644 --- a/src/main/java/ch/dissem/msgpack/types/Utils.java +++ b/src/main/java/ch/dissem/msgpack/types/Utils.java @@ -20,8 +20,9 @@ import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; -class Utils { +public class Utils { private static final char[] BASE64_CODES = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".toCharArray(); + private static final MPNil NIL = new MPNil(); /** * Returns a {@link ByteBuffer} containing the next count bytes from the {@link InputStream}. @@ -83,4 +84,32 @@ class Utils { 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; + } }