序列化

简介: 本文从源码角度解析Zookeeper的序列化机制,重点分析jute包中的InputArchive和OutputArchive接口及其实现类,涵盖基本类型与记录的序列化过程,揭示其在网络通信与数据存储中的核心作用。

一、前言  在完成了前面的理论学习后,现在可以从源码角度来解析Zookeeper的细节,首先笔者想从序列化入手,因为在网络通信、数据存储中都用到了序列化,下面开始分析。二、序列化  序列化主要在zookeeper.jute包中,其中涉及的主要接口如下    · InputArchive    · OutputArchive    · Index    · Record2.1 InputArchive  其是所有反序列化器都需要实现的接口,其方法如下 InputArchive的类结构如下  1. BinaryInputArchive 2. CsvInputArchive 3. XmlInputArchive2.2 OutputArchive  其是所有序列化器都需要实现此接口,其方法如下。  OutputArchive的类结构如下  1. BinaryOutputArchive 2. CsvOutputArchive 3. XmlOutputArchive

Java

运行代码复制代码

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

/**

// 写boolean类型

public void writeBool(boolean b, String tag) throws IOException {

printBeginEnvelope(tag);

stream.print("<boolean>");

stream.print(b ? "1" : "0");

stream.print("</boolean>");

printEndEnvelope(tag);

}

// 写int类型

public void writeInt(int i, String tag) throws IOException {

printBeginEnvelope(tag);

stream.print("<i4>");

stream.print(Integer.toString(i));

stream.print("</i4>");

printEndEnvelope(tag);

}

// 写long类型

public void writeLong(long l, String tag) throws IOException {

printBeginEnvelope(tag);

stream.print("<ex:i8>");

stream.print(Long.toString(l));

stream.print("</ex:i8>");

printEndEnvelope(tag);

}

// 写float类型

public void writeFloat(float f, String tag) throws IOException {

printBeginEnvelope(tag);

stream.print("<ex:float>");

stream.print(Float.toString(f));

stream.print("</ex:float>");

printEndEnvelope(tag);

}

// 写double类型

public void writeDouble(double d, String tag) throws IOException {

printBeginEnvelope(tag);

stream.print("<double>");

stream.print(Double.toString(d));

stream.print("</double>");

printEndEnvelope(tag);

}

// 写String类型

public void writeString(String s, String tag) throws IOException {

printBeginEnvelope(tag);

stream.print("<string>");

stream.print(Utils.toXMLString(s));

stream.print("</string>");

printEndEnvelope(tag);

}

// 写Buffer类型

public void writeBuffer(byte buf[], String tag)

throws IOException {

printBeginEnvelope(tag);

stream.print("<string>");

stream.print(Utils.toXMLBuffer(buf));

stream.print("</string>");

printEndEnvelope(tag);

}

// 写Record类型

public void writeRecord(Record r, String tag) throws IOException {

r.serialize(this, tag);

}

// 开始写Record类型

public void startRecor

相关文章
|
12天前
|
数据采集 人工智能 安全
|
7天前
|
机器学习/深度学习 人工智能 前端开发
构建AI智能体:七十、小树成林,聚沙成塔:随机森林与大模型的协同进化
随机森林是一种基于决策树的集成学习算法,通过构建多棵决策树并结合它们的预测结果来提高准确性和稳定性。其核心思想包括两个随机性:Bootstrap采样(每棵树使用不同的训练子集)和特征随机选择(每棵树分裂时只考虑部分特征)。这种方法能有效处理大规模高维数据,避免过拟合,并评估特征重要性。随机森林的超参数如树的数量、最大深度等可通过网格搜索优化。该算法兼具强大预测能力和工程化优势,是机器学习中的常用基础模型。
344 164
|
6天前
|
机器学习/深度学习 自然语言处理 机器人
阿里云百炼大模型赋能|打造企业级电话智能体与智能呼叫中心完整方案
畅信达基于阿里云百炼大模型推出MVB2000V5智能呼叫中心方案,融合LLM与MRCP+WebSocket技术,实现语音识别率超95%、低延迟交互。通过电话智能体与座席助手协同,自动化处理80%咨询,降本增效显著,适配金融、电商、医疗等多行业场景。
345 155
|
7天前
|
编解码 人工智能 自然语言处理
⚽阿里云百炼通义万相 2.6 视频生成玩法手册
通义万相Wan 2.6是全球首个支持角色扮演的AI视频生成模型,可基于参考视频形象与音色生成多角色合拍、多镜头叙事的15秒长视频,实现声画同步、智能分镜,适用于影视创作、营销展示等场景。
582 4
|
15天前
|
SQL 自然语言处理 调度
Agent Skills 的一次工程实践
**本文采用 Agent Skills 实现整体智能体**,开发框架采用 AgentScope,模型使用 **qwen3-max**。Agent Skills 是 Anthropic 新推出的一种有别于mcp server的一种开发方式,用于为 AI **引入可共享的专业技能**。经验封装到**可发现、可复用的能力单元**中,每个技能以文件夹形式存在,包含特定任务的指导性说明(SKILL.md 文件)、脚本代码和资源等 。大模型可以根据需要动态加载这些技能,从而扩展自身的功能。目前不少国内外的一些框架也开始支持此种的开发方式,详细介绍如下。
1019 7