既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上软件测试知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
static class tester implements marshallable {
int age
string name
tester(string name, int age) {
this.name = name
this.age = age
}
}
static void main(string… args) {
classaliaspool.class_aliases.addalias(tester.class)//允许 yaml 引用 tester,而不是 net.openhft.chronicle.wire.wiredemo$tester
wire wire = new yamlwire(bytes.allocateelasticonheap())//yamlwire 用于 yaml 格式的数据
wire.getvalueout().object(new tester(“funtester”, 18))//将对象写入 wire system.out.println(wire)//打印 wire }
}
控制台输出:
!tester {
number: 18,
driver: funtester
}
如果我们换成jsonwire,如下:
wire wire = new jsonwire(bytes.allocateelasticonheap())// 创建一个 jsonwire
如果我们希望json也包含java类型,那么我们还可以如下设置:
wire wire = new jsonwire(bytes.allocateelasticonheap()).usetypes(true)// 创建一个 jsonwire,使用类型
这也将编码java类型tester:
{“@tester”:{“age”:18,“name”:“funtester”}}
## 二进制格式
让我们继续一个使用紧凑二进制格式的示例:
static void main(string[] args) {
classaliaspool.class_aliases.addalias(tester.class)
wire wire = wiretype.fieldless_binary.apply(bytes.allocateelasticonheap())
wire.getvalueout().object(new tester(“funtester”, 18))
system.out.println(wire.bytes().tohexstring())
}
其输出如下:
00000000 b6 06 54 65 73 74 65 72 82 0c 00 00 00 a1 12 e9 ··tester ········
00000010 46 75 6e 54 65 73 74 65 72 funteste r
## 实例反序列化
到目前为止,所有的例子都涵盖了序列化,所以当涉及到序列化时,我们可以从数据开始,例如:
{“@car”:{“number”:44,“driver”:“lewis hamilton”}}
然后我们可以将这个json转换回java对象:
static void main(string[] args) {
classaliaspool.class_aliases.addalias(tester.class) // 注册 tester 类的别名
wire wire = new jsonwire().usetypes(true)// 创建 jsonwire 实例并启用类型信息
wire.bytes().append(“{”@tester":{“age”:18,“name”:“funtester”}}") // 在 wire 中追加 json 格式的字符串
object object = wire.getvaluein().object()// 从 wire 中获取对象
println object.getclass().getname() // 输出对象的类型
def tester = (tester) object // 将对象转换为 tester 类型
println tester.name
println tester.age
}
控制台输出:
com.funtest.queue.wiredemo$tester
funtester
18
## 兼容性
如果字段名被编码,如果我们改变对象属性,包括`int height`(见下面的例子),这些数值将只是默认为零,当重新定义发生时,该字段将像往常一样加载。
import net.openhft.chronicle.core.pool.classaliaspool
import net.openhft.chronicle.wire.jsonwire
import net.openhft.chronicle.wire.marshallable
import net.openhft.chronicle.wire.wire
/**
* chronicle-queue,wire 案例
*/
class wiredemo {
static class tester implements marshallable {
int age
string name
int height
tester(string name, int age) {
this.name = name
this.age = age
}
}
static void main(string[] args) {
classaliaspool.class_aliases.addalias(tester.class) // 注册 tester 类的别名
wire wire = new jsonwire().usetypes(true)// 创建 jsonwire 实例并启用类型信息
wire.bytes().append(“{”@tester":{“age”:18,“name”:“funtester”}}") // 在 wire 中追加 json 格式的字符串
object object = wire.getvaluein().object()// 从 wire 中获取对象
println object.getclass().getname() // 输出对象的类型
def tester = (tester) object // 将对象转换为 tester 类型
println tester.name
println tester.age
println tester.height
}
}
控制台打印如下:
com.funtest.queue.wiredemo$tester
funtester
18
0
## 字符串
通常,字符串使用utf8标准编码,然而,字符串也可以使用`base encoder`编码,例如base64编码器,它可以将数据存储到更紧凑的字符串或原语字段中。每个字节有256种不同的组合(这是因为一个字节由8位组成,位是0或1,给出2^8个组合,因此是256),然而,如果我们选择使用基本编码器,并假设我们可以将字符串限制为以下字符“.abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz0123456789+”这是一些最常用的字符,那么我们可以使用这个基本编码器将上面的10个字符存储到8个字节中。
我们可以创建自己的基本编码,它不只是必须包含这个数量的字符。使用更少的字符,可以从更大的紧凑性中受益。如前所述,数据越紧凑,读写速度就越快。
下面是一个chronicle wire如何将小字符串存储在长字符串中的例子,yaml序列化器显示了字符串表示,但字符串仅使用8字节长存储在对象中,同样,二进制序列化器将使用更紧凑的8字节长表示。
static class funtext extends selfdescribingmarshallable {
transient stringbuilder temp = new stringbuilder()
@longconversion(base64longconverter.class)
long text
funtext(charsequence text) {
this.text = base64longconverter.instance.parse(text)
}
charsequence text() {
base64longconverter.instance.append(temp, text)
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事it行业的老鸟或是对it行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事it行业的老鸟或是对it行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
发表评论