java结构体_javastruct()关于java结构体.doc

javastruct()关于java结构体

javastruct

A library to treat java objects as C structs.窗体顶端

窗体底端

HYPERLINK "/p/javastruct/"Project HomeHYPERLINK "/p/javastruct/downloads/list"DownloadsHYPERLINK "/p/javastruct/w/list"WikiHYPERLINK "/p/javastruct/issues/list"IssuesHYPERLINK "/p/javastruct/source/checkout"Source

Search 窗体顶端

for

窗体底端

HowToUseJavaStruct

This page explains how to use JavaStruct library. HYPERLINK "/p/javastruct/w/list?q=label:Featured"Featured, HYPERLINK "/p/javastruct/w/list?q=label:Phase-Implementation"Phase-Implementation

Updated Feb 4, 2010 by HYPERLINK "/u/102564017663053832542/"mda...@

Introduction

Struct classes can be used to greatly simplfy network protocol codes of Java applications when working with embedded devices and other applications which uses C style structs.

Instead of manually encoding and decoding messages, JavaStruct allows programmers to treat java classes as c structs.

JavaStruct uses Java 5 annotations to mark Classes and fields as structs. JavaStruct is not the first attempt to provide struct like functionality, Jean-Marie Dautelle's HYPERLINK "/"Javolution library also has an excellent HYPERLINK "/api/javolution/io/Struct.html"struct implementation. But instead of using special classes in Javolution, POJO approach is preferred JavaStruct.

General usage

JavaStruct fa?ade class is used to pack and unpack struct classes. Below is a simple unit test method for checking a struct class. Struct fields hasan order value, because Java JVM specification does not tell anything about order of the class members. They are ordered as their appearance in Sun's implementation but it differs on other JVM's. So every Struct field has to supply an order value.

@StructClasspublic class Foo{ @StructField(order = 0) public byte b; @StructField(order = 1) public int i;}try{ // Pack the class as a byte buffer Foo f = new Foo(); //媒体处理器 f.b = (byte)1; f.i = 1; byte[] b = JavaStruct.pack(f); // Unpack

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值