目录

菠萝🍍的博客

有谁不喜欢吃菠萝呢

X

MessagePack for Java开发指南

github上MessagePack for Java机翻译:来源

MessagePack 是二进制序列化格式。如果您需要快速,紧凑的JSON替代方案,那么MessagePack是您的朋友。例如,可以将一个小整数编码为一个字节,而短字符串则只需要一个字节前缀+原始字节数组即可。MessagePack实现已经有多种语言可用(另请参见http://msgpack.org中的列表),并且可以作为通用数据格式使用.

MessagePack v7 (或者之后的版本) 是较早版本的更快实现v06, 支持所有消息包类型, 包括extension format.

JavaDoc可从javadoc.io获得.

Quick Start

Maven Central
Javadoc

For Maven users:

<dependency>
   <groupId>org.msgpack</groupId>
   <artifactId>msgpack-core</artifactId>
   <version>(version)</version>
</dependency>

For sbt users:

libraryDependencies += "org.msgpack" % "msgpack-core" % "(version)"

For gradle users:

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.msgpack:msgpack-core:(version)'
}

与Jackson的ObjectMapper集成 (jackson-databind)

msgpack-java支持通过以下方式对Java对象进行序列化和反序列化jackson-databind.
有关详细信息,请参见 msgpack-jackson/README.md.v06中使用的基于模板的序列化机制已被弃用

对于MessagePack开发人员 Travis CI

msgpack-java 使用sbt 构建项目. 有关sbt的基本用法,请参见:

编码风格

基本sbt命令

Enter the sbt console:

$ ./sbt

这是日常开发的sbt命令列表:

> ~compile                                 # Compile source codes
> ~test:compile                            # Compile both source and test codes
> ~test                                    # Run tests upon source code change
> ~testOnly *MessagePackTest               # Run tests in the specified class
> ~testOnly *MessagePackTest -- -n prim    # Run the test tagged as "prim"
> project msgpack-core                     # Focus on a specific project
> package                                  # Create a jar file in the target folder of each project
> findbugs                                 # Produce findbugs report in target/findbugs
> jacoco:cover                             # Report the code coverage of tests to target/jacoco folder
> jcheckStyle                              # Run check style
> ;scalafmt;test:scalafmt;scalafmtSbt      # Reformat Scala codes

出版

> publishLocal            # Install to local .ivy2 repository
> publishM2               # Install to local .m2 Maven repository
> publish                 # Publishing a snapshot version to the Sonatype repository

> release                 # Run the release procedure (set a new version, run tests, upload artifacts, then deploy to Sonatype)

# 如果需要手动执行各个发布步骤,请使用以下命令:
> publishSigned           # Publish GPG signed artifacts to the Sonatype repository
> sonatypeRelease         # Publish to the Maven Central (It will be synched within less than 4 hours)

为了发布到Maven中央,msgpack-java使用sbt-sonatype plugin. Set Sonatype account information (user name and password) in the global sbt settings. To protect your password, never include this file in your project.

$HOME/.sbt/(sbt-version)/sonatype.sbt

credentials += Credentials("Sonatype Nexus Repository Manager",
        "oss.sonatype.org",
        "(Sonatype user name)",
        "(Sonatype password)")

Project Structure

msgpack-core                 # Contains packer/unpacker implementation that never uses third-party libraries
msgpack-jackson              # Contains jackson-dataformat-java implementation

标题:MessagePack for Java开发指南
作者:MingGH
地址:https://runnable.run/articles/2020/03/09/1583723550690.html