Skip to content

msgpack-core v07 API #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2014
Merged

msgpack-core v07 API #82

merged 1 commit into from
May 15, 2014

Conversation

xerial
Copy link
Member

@xerial xerial commented May 9, 2014

I wrote a draft code of msgpack-core for v07, which is a low-level module for reading/writing data in the Message Pack format (https://github.com/msgpack/msgpack/blob/master/spec.md).

Please review the design of this msgpack-core API in terms of the performance, usability and class/method naming. After the review I will add some test code to complete the implementation.

The goal of msgpack-core is to provide a low-level packer and unpacker implementation that is faster than v06. So, several rich functions (e.g., Template generation, JSON support) will not be implemented in msgpack-core v07.

msgpack-core API includes the following classes:

MessageBuffer

  • For reading/writing primitive type values in a memory
  • getXXX for reading values, putXXX for writing values
  • This class uses sun.misc.Unsafe API to read the data in memory as fast as possible
  • The specification of message pack requires writing short/int/float/long/double values in big-endian. The default implementation translates little-endian values into big-endian. MessageBufferBE that does not translate the endian will be used for big-endian machine.
  • This API tries to remove invokeinterface call to achieve the highest performance. So MessageBuffer does not implement any interface, and also to avoid the cost of TypeProfile lookup in JVM, only one of MessageBuffer or MessageBufferBE classes is loaded at runtime (using reflection).

MessagePacker

  • packInt, packBoolean, ... for writing message-packed values
  • writePayload for writing binary/raw string data

MessageBufferOutput

  • Used in MessagePacker to output message-packed data to a stream or buffer
  • This is an adapter to OutputStream or WritableByteChannel

MessageUnpacker

  • unpackInt, unpackBoolean, ... for reading message-packed values
  • readPayload for reading binary/raw string data
  • To read message pack data, first call getMessageType. The user need to select an appropriate unpackXXX method according to the given MessageType (enum).

MesasgeBufferInput

  • Used in MessageUnpacker to retrieve a sequence of MessageBuffer that contains message packed data
  • This is an adapter to InputStream or ReadableByteChannel

MesasgePackException

  • The base class of all message-pack exceptions.
  • MessageTypeException for type mismatch errors
  • MessageFormatException for invalid inputs

MessageFormat

  • Enum definition that covers all of the format types in the specification

ValueType

  • ValueType represents a group of MessageFormats. For example ValueType.INTEGER is a group of MessageFormat.INT8, INT16, .. UINT8, etc.

MessagePack

  • Provides utility methods for creating packer and unpacker.

@frsyuki frsyuki added this to the v07 milestone May 9, 2014
* using a smaller types. For example, calling MessageUnpacker.unpackInt() for an integer value
* that is larger than Integer.MAX_VALUE will cause this exception.
*/
public class MessageIntegerOverflowException extends MessageTypeException {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Consistent name with MessageStringCodingException

@oza
Copy link
Member

oza commented May 10, 2014

Should we add license information to headers?

//
// MessagePack for Java
//
//    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.
//

this.writeBufferChunkSize = builder.getWriteBufferChunkSize();
this.readReferenceThreshold = builder.getReadReferenceThreshold();
}
private AtomicInteger referenceCounter;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable looks unused variable. Do you have any plan to support GC-like feature by using reference counter in this class? If the answer is positive, should we write it down as TODO comment?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm considering managing allocated MssageBuffer(s) via GC or releasing explicitly, but this feature is not yet implemented. right. It should be marked as TODO.

@oza
Copy link
Member

oza commented May 10, 2014

Can we add javax.annotation.Nullable annotation to user-facing APIs? It's useful for users to understand whether arguments and return values can be null or not.

private final WritableByteChannel channel;

MessageBufferOutputChannel(WritableByteChannel channel) {
this.channel = channel;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as MessageBufferOutputStream's constructor(need null check?).

ArrayList<MessageBuffer> bufferList = new ArrayList<MessageBuffer>();
while(bufferTotal < readSize) {
MessageBuffer next = in.next();
if(next == null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you set reachedEOF to true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@komamitsu
Copy link
Member

Other than those minor comments, it looks good. GJ!

@xerial
Copy link
Member Author

xerial commented May 15, 2014

I extracted several remaining issues discussed here as tickets:
https://github.com/msgpack/msgpack-java/issues?milestone=1&state=open

I'm going to merge these changes into v07 branch.

@xerial xerial merged commit 1620ca0 into v07 May 15, 2014
xerial added a commit that referenced this pull request May 15, 2014
@oza
Copy link
Member

oza commented May 17, 2014

GJ, @xerial!

@xerial xerial deleted the v07-draft branch May 22, 2014 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants