001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.marshall; 014 015import org.apache.juneau.msgpack.*; 016 017/** 018 * A pairing of a {@link MsgPackSerializer} and {@link MsgPackParser} into a single class with convenience read/write methods. 019 * 020 * <p> 021 * The general idea is to combine a single serializer and parser inside a simplified API for reading and writing POJOs. 022 * 023 * <h5 class='figure'>Examples:</h5> 024 * <p class='bcode w800'> 025 * <jc>// Using instance.</jc> 026 * MsgPack msgPack = <jk>new</jk> MsgPack(); 027 * MyPojo myPojo = msgPack.read(bytes, MyPojo.<jk>class</jk>); 028 * <jk>byte</jk>[] bytes = msgPack.write(myPojo); 029 * </p> 030 * <p class='bcode w800'> 031 * <jc>// Using DEFAULT instance.</jc> 032 * MyPojo myPojo = MsgPack.<jsf>DEFAULT</jsf>.read(bytes, MyPojo.<jk>class</jk>); 033 * <jk>byte</jk>[] bytes = MsgPack.<jsf>DEFAULT</jsf>.write(myPojo); 034 * </p> 035 * 036 * <ul class='seealso'> 037 * <li class='link'>{@doc juneau-marshall.Marshalls} 038 * </ul> 039 */ 040public class MsgPack extends StreamMarshall { 041 042 /** 043 * Default reusable instance. 044 */ 045 public static final MsgPack DEFAULT = new MsgPack(); 046 047 /** 048 * Constructor. 049 * 050 * @param s 051 * The serializer to use for serializing output. 052 * <br>Must not be <jk>null</jk>. 053 * @param p 054 * The parser to use for parsing input. 055 * <br>Must not be <jk>null</jk>. 056 */ 057 public MsgPack(MsgPackSerializer s, MsgPackParser p) { 058 super(s, p); 059 } 060 061 /** 062 * Constructor. 063 * 064 * <p> 065 * Uses {@link MsgPackSerializer#DEFAULT} and {@link MsgPackParser#DEFAULT}. 066 */ 067 public MsgPack() { 068 this(MsgPackSerializer.DEFAULT, MsgPackParser.DEFAULT); 069 } 070}