mirror of
https://github.com/tiennm99/try-netty.git
synced 2026-06-01 22:13:01 +00:00
[Add] 2 channelHandlers for json and fbs
This commit is contained in:
@@ -0,0 +1 @@
|
||||
.idea
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Title</title>
|
||||
<script src="flatbuffers.js"></script>
|
||||
<script src="sample_generated.js"></script>
|
||||
<script src="script.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,575 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @namespace
|
||||
*/
|
||||
var MyGame = MyGame || {};
|
||||
|
||||
/**
|
||||
* @const
|
||||
* @namespace
|
||||
*/
|
||||
MyGame.Sample = MyGame.Sample || {};
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
MyGame.Sample.Color = {
|
||||
Red: 0,
|
||||
Green: 1,
|
||||
Blue: 2
|
||||
};
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
MyGame.Sample.ColorName = {
|
||||
'0': 'Red',
|
||||
'1': 'Green',
|
||||
'2': 'Blue'
|
||||
};
|
||||
|
||||
/**
|
||||
* @enum {number}
|
||||
*/
|
||||
MyGame.Sample.Equipment = {
|
||||
NONE: 0,
|
||||
Weapon: 1
|
||||
};
|
||||
|
||||
/**
|
||||
* @enum {string}
|
||||
*/
|
||||
MyGame.Sample.EquipmentName = {
|
||||
'0': 'NONE',
|
||||
'1': 'Weapon'
|
||||
};
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
MyGame.Sample.Vec3 = function() {
|
||||
/**
|
||||
* @type {flatbuffers.ByteBuffer}
|
||||
*/
|
||||
this.bb = null;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.bb_pos = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} i
|
||||
* @param {flatbuffers.ByteBuffer} bb
|
||||
* @returns {MyGame.Sample.Vec3}
|
||||
*/
|
||||
MyGame.Sample.Vec3.prototype.__init = function(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Vec3.prototype.x = function() {
|
||||
return this.bb.readFloat32(this.bb_pos);
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Vec3.prototype.y = function() {
|
||||
return this.bb.readFloat32(this.bb_pos + 4);
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Vec3.prototype.z = function() {
|
||||
return this.bb.readFloat32(this.bb_pos + 8);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {number} x
|
||||
* @param {number} y
|
||||
* @param {number} z
|
||||
* @returns {flatbuffers.Offset}
|
||||
*/
|
||||
MyGame.Sample.Vec3.createVec3 = function(builder, x, y, z) {
|
||||
builder.prep(4, 12);
|
||||
builder.writeFloat32(z);
|
||||
builder.writeFloat32(y);
|
||||
builder.writeFloat32(x);
|
||||
return builder.offset();
|
||||
};
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
MyGame.Sample.Monster = function() {
|
||||
/**
|
||||
* @type {flatbuffers.ByteBuffer}
|
||||
*/
|
||||
this.bb = null;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.bb_pos = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} i
|
||||
* @param {flatbuffers.ByteBuffer} bb
|
||||
* @returns {MyGame.Sample.Monster}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.__init = function(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.ByteBuffer} bb
|
||||
* @param {MyGame.Sample.Monster=} obj
|
||||
* @returns {MyGame.Sample.Monster}
|
||||
*/
|
||||
MyGame.Sample.Monster.getRootAsMonster = function(bb, obj) {
|
||||
return (obj || new MyGame.Sample.Monster).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.ByteBuffer} bb
|
||||
* @param {MyGame.Sample.Monster=} obj
|
||||
* @returns {MyGame.Sample.Monster}
|
||||
*/
|
||||
MyGame.Sample.Monster.getSizePrefixedRootAsMonster = function(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new MyGame.Sample.Monster).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {MyGame.Sample.Vec3=} obj
|
||||
* @returns {MyGame.Sample.Vec3|null}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.pos = function(obj) {
|
||||
var offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? (obj || new MyGame.Sample.Vec3).__init(this.bb_pos + offset, this.bb) : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.mana = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readInt16(this.bb_pos + offset) : 150;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.hp = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 8);
|
||||
return offset ? this.bb.readInt16(this.bb_pos + offset) : 100;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Encoding=} optionalEncoding
|
||||
* @returns {string|Uint8Array|null}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.name = function(optionalEncoding) {
|
||||
var offset = this.bb.__offset(this.bb_pos, 10);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} index
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.inventory = function(index) {
|
||||
var offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.readUint8(this.bb.__vector(this.bb_pos + offset) + index) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.inventoryLength = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {Uint8Array}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.inventoryArray = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 14);
|
||||
return offset ? new Uint8Array(this.bb.bytes().buffer, this.bb.bytes().byteOffset + this.bb.__vector(this.bb_pos + offset), this.bb.__vector_len(this.bb_pos + offset)) : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {MyGame.Sample.Color}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.color = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 16);
|
||||
return offset ? /** @type {MyGame.Sample.Color} */ (this.bb.readInt8(this.bb_pos + offset)) : MyGame.Sample.Color.Blue;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} index
|
||||
* @param {MyGame.Sample.Weapon=} obj
|
||||
* @returns {MyGame.Sample.Weapon}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.weapons = function(index, obj) {
|
||||
var offset = this.bb.__offset(this.bb_pos, 18);
|
||||
return offset ? (obj || new MyGame.Sample.Weapon).__init(this.bb.__indirect(this.bb.__vector(this.bb_pos + offset) + index * 4), this.bb) : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.weaponsLength = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 18);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {MyGame.Sample.Equipment}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.equippedType = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 20);
|
||||
return offset ? /** @type {MyGame.Sample.Equipment} */ (this.bb.readUint8(this.bb_pos + offset)) : MyGame.Sample.Equipment.NONE;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Table} obj
|
||||
* @returns {?flatbuffers.Table}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.equipped = function(obj) {
|
||||
var offset = this.bb.__offset(this.bb_pos, 22);
|
||||
return offset ? this.bb.__union(obj, this.bb_pos + offset) : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} index
|
||||
* @param {MyGame.Sample.Vec3=} obj
|
||||
* @returns {MyGame.Sample.Vec3}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.path = function(index, obj) {
|
||||
var offset = this.bb.__offset(this.bb_pos, 24);
|
||||
return offset ? (obj || new MyGame.Sample.Vec3).__init(this.bb.__vector(this.bb_pos + offset) + index * 12, this.bb) : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Monster.prototype.pathLength = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 24);
|
||||
return offset ? this.bb.__vector_len(this.bb_pos + offset) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
*/
|
||||
MyGame.Sample.Monster.startMonster = function(builder) {
|
||||
builder.startObject(11);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} posOffset
|
||||
*/
|
||||
MyGame.Sample.Monster.addPos = function(builder, posOffset) {
|
||||
builder.addFieldStruct(0, posOffset, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {number} mana
|
||||
*/
|
||||
MyGame.Sample.Monster.addMana = function(builder, mana) {
|
||||
builder.addFieldInt16(1, mana, 150);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {number} hp
|
||||
*/
|
||||
MyGame.Sample.Monster.addHp = function(builder, hp) {
|
||||
builder.addFieldInt16(2, hp, 100);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} nameOffset
|
||||
*/
|
||||
MyGame.Sample.Monster.addName = function(builder, nameOffset) {
|
||||
builder.addFieldOffset(3, nameOffset, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} inventoryOffset
|
||||
*/
|
||||
MyGame.Sample.Monster.addInventory = function(builder, inventoryOffset) {
|
||||
builder.addFieldOffset(5, inventoryOffset, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {Array.<number>} data
|
||||
* @returns {flatbuffers.Offset}
|
||||
*/
|
||||
MyGame.Sample.Monster.createInventoryVector = function(builder, data) {
|
||||
builder.startVector(1, data.length, 1);
|
||||
for (var i = data.length - 1; i >= 0; i--) {
|
||||
builder.addInt8(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {number} numElems
|
||||
*/
|
||||
MyGame.Sample.Monster.startInventoryVector = function(builder, numElems) {
|
||||
builder.startVector(1, numElems, 1);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {MyGame.Sample.Color} color
|
||||
*/
|
||||
MyGame.Sample.Monster.addColor = function(builder, color) {
|
||||
builder.addFieldInt8(6, color, MyGame.Sample.Color.Blue);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} weaponsOffset
|
||||
*/
|
||||
MyGame.Sample.Monster.addWeapons = function(builder, weaponsOffset) {
|
||||
builder.addFieldOffset(7, weaponsOffset, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {Array.<flatbuffers.Offset>} data
|
||||
* @returns {flatbuffers.Offset}
|
||||
*/
|
||||
MyGame.Sample.Monster.createWeaponsVector = function(builder, data) {
|
||||
builder.startVector(4, data.length, 4);
|
||||
for (var i = data.length - 1; i >= 0; i--) {
|
||||
builder.addOffset(data[i]);
|
||||
}
|
||||
return builder.endVector();
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {number} numElems
|
||||
*/
|
||||
MyGame.Sample.Monster.startWeaponsVector = function(builder, numElems) {
|
||||
builder.startVector(4, numElems, 4);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {MyGame.Sample.Equipment} equippedType
|
||||
*/
|
||||
MyGame.Sample.Monster.addEquippedType = function(builder, equippedType) {
|
||||
builder.addFieldInt8(8, equippedType, MyGame.Sample.Equipment.NONE);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} equippedOffset
|
||||
*/
|
||||
MyGame.Sample.Monster.addEquipped = function(builder, equippedOffset) {
|
||||
builder.addFieldOffset(9, equippedOffset, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} pathOffset
|
||||
*/
|
||||
MyGame.Sample.Monster.addPath = function(builder, pathOffset) {
|
||||
builder.addFieldOffset(10, pathOffset, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {number} numElems
|
||||
*/
|
||||
MyGame.Sample.Monster.startPathVector = function(builder, numElems) {
|
||||
builder.startVector(12, numElems, 4);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @returns {flatbuffers.Offset}
|
||||
*/
|
||||
MyGame.Sample.Monster.endMonster = function(builder) {
|
||||
var offset = builder.endObject();
|
||||
return offset;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} offset
|
||||
*/
|
||||
MyGame.Sample.Monster.finishMonsterBuffer = function(builder, offset) {
|
||||
builder.finish(offset);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} offset
|
||||
*/
|
||||
MyGame.Sample.Monster.finishSizePrefixedMonsterBuffer = function(builder, offset) {
|
||||
builder.finish(offset, undefined, true);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} posOffset
|
||||
* @param {number} mana
|
||||
* @param {number} hp
|
||||
* @param {flatbuffers.Offset} nameOffset
|
||||
* @param {flatbuffers.Offset} inventoryOffset
|
||||
* @param {MyGame.Sample.Color} color
|
||||
* @param {flatbuffers.Offset} weaponsOffset
|
||||
* @param {MyGame.Sample.Equipment} equippedType
|
||||
* @param {flatbuffers.Offset} equippedOffset
|
||||
* @param {flatbuffers.Offset} pathOffset
|
||||
* @returns {flatbuffers.Offset}
|
||||
*/
|
||||
MyGame.Sample.Monster.createMonster = function(builder, posOffset, mana, hp, nameOffset, inventoryOffset, color, weaponsOffset, equippedType, equippedOffset, pathOffset) {
|
||||
MyGame.Sample.Monster.startMonster(builder);
|
||||
MyGame.Sample.Monster.addPos(builder, posOffset);
|
||||
MyGame.Sample.Monster.addMana(builder, mana);
|
||||
MyGame.Sample.Monster.addHp(builder, hp);
|
||||
MyGame.Sample.Monster.addName(builder, nameOffset);
|
||||
MyGame.Sample.Monster.addInventory(builder, inventoryOffset);
|
||||
MyGame.Sample.Monster.addColor(builder, color);
|
||||
MyGame.Sample.Monster.addWeapons(builder, weaponsOffset);
|
||||
MyGame.Sample.Monster.addEquippedType(builder, equippedType);
|
||||
MyGame.Sample.Monster.addEquipped(builder, equippedOffset);
|
||||
MyGame.Sample.Monster.addPath(builder, pathOffset);
|
||||
return MyGame.Sample.Monster.endMonster(builder);
|
||||
}
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*/
|
||||
MyGame.Sample.Weapon = function() {
|
||||
/**
|
||||
* @type {flatbuffers.ByteBuffer}
|
||||
*/
|
||||
this.bb = null;
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
this.bb_pos = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {number} i
|
||||
* @param {flatbuffers.ByteBuffer} bb
|
||||
* @returns {MyGame.Sample.Weapon}
|
||||
*/
|
||||
MyGame.Sample.Weapon.prototype.__init = function(i, bb) {
|
||||
this.bb_pos = i;
|
||||
this.bb = bb;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.ByteBuffer} bb
|
||||
* @param {MyGame.Sample.Weapon=} obj
|
||||
* @returns {MyGame.Sample.Weapon}
|
||||
*/
|
||||
MyGame.Sample.Weapon.getRootAsWeapon = function(bb, obj) {
|
||||
return (obj || new MyGame.Sample.Weapon).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.ByteBuffer} bb
|
||||
* @param {MyGame.Sample.Weapon=} obj
|
||||
* @returns {MyGame.Sample.Weapon}
|
||||
*/
|
||||
MyGame.Sample.Weapon.getSizePrefixedRootAsWeapon = function(bb, obj) {
|
||||
bb.setPosition(bb.position() + flatbuffers.SIZE_PREFIX_LENGTH);
|
||||
return (obj || new MyGame.Sample.Weapon).__init(bb.readInt32(bb.position()) + bb.position(), bb);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Encoding=} optionalEncoding
|
||||
* @returns {string|Uint8Array|null}
|
||||
*/
|
||||
MyGame.Sample.Weapon.prototype.name = function(optionalEncoding) {
|
||||
var offset = this.bb.__offset(this.bb_pos, 4);
|
||||
return offset ? this.bb.__string(this.bb_pos + offset, optionalEncoding) : null;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {number}
|
||||
*/
|
||||
MyGame.Sample.Weapon.prototype.damage = function() {
|
||||
var offset = this.bb.__offset(this.bb_pos, 6);
|
||||
return offset ? this.bb.readInt16(this.bb_pos + offset) : 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
*/
|
||||
MyGame.Sample.Weapon.startWeapon = function(builder) {
|
||||
builder.startObject(2);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} nameOffset
|
||||
*/
|
||||
MyGame.Sample.Weapon.addName = function(builder, nameOffset) {
|
||||
builder.addFieldOffset(0, nameOffset, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {number} damage
|
||||
*/
|
||||
MyGame.Sample.Weapon.addDamage = function(builder, damage) {
|
||||
builder.addFieldInt16(1, damage, 0);
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @returns {flatbuffers.Offset}
|
||||
*/
|
||||
MyGame.Sample.Weapon.endWeapon = function(builder) {
|
||||
var offset = builder.endObject();
|
||||
return offset;
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {flatbuffers.Builder} builder
|
||||
* @param {flatbuffers.Offset} nameOffset
|
||||
* @param {number} damage
|
||||
* @returns {flatbuffers.Offset}
|
||||
*/
|
||||
MyGame.Sample.Weapon.createWeapon = function(builder, nameOffset, damage) {
|
||||
MyGame.Sample.Weapon.startWeapon(builder);
|
||||
MyGame.Sample.Weapon.addName(builder, nameOffset);
|
||||
MyGame.Sample.Weapon.addDamage(builder, damage);
|
||||
return MyGame.Sample.Weapon.endWeapon(builder);
|
||||
}
|
||||
|
||||
// Exports for Node.js and RequireJS
|
||||
this.MyGame = MyGame;
|
||||
@@ -0,0 +1,81 @@
|
||||
let fbsSocket = new WebSocket("ws://localhost:1202/fbs");
|
||||
fbsSocket.binaryType = 'arraybuffer';
|
||||
|
||||
fbsSocket.onopen = function () {
|
||||
sendFbs();
|
||||
};
|
||||
|
||||
let sendFbs = function () {
|
||||
var builder = new flatbuffers.Builder(1024);
|
||||
var weaponOne = builder.createString('Sword');
|
||||
var weaponTwo = builder.createString('Axe');
|
||||
|
||||
// Create the first `Weapon` ('Sword').
|
||||
MyGame.Sample.Weapon.startWeapon(builder);
|
||||
MyGame.Sample.Weapon.addName(builder, weaponOne);
|
||||
MyGame.Sample.Weapon.addDamage(builder, 3);
|
||||
var sword = MyGame.Sample.Weapon.endWeapon(builder);
|
||||
|
||||
// Create the second `Weapon` ('Axe').
|
||||
MyGame.Sample.Weapon.startWeapon(builder);
|
||||
MyGame.Sample.Weapon.addName(builder, weaponTwo);
|
||||
MyGame.Sample.Weapon.addDamage(builder, 5);
|
||||
var axe = MyGame.Sample.Weapon.endWeapon(builder);
|
||||
// Serialize a name for our monster, called 'Orc'.
|
||||
var name = builder.createString('Orc');
|
||||
|
||||
// Create a `vector` representing the inventory of the Orc. Each number
|
||||
// could correspond to an item that can be claimed after he is slain.
|
||||
var treasure = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
||||
var inv = MyGame.Sample.Monster.createInventoryVector(builder, treasure);
|
||||
// Create an array from the two `Weapon`s and pass it to the
|
||||
// `createWeaponsVector()` method to create a FlatBuffer vector.
|
||||
var weaps = [sword, axe];
|
||||
var weapons = MyGame.Sample.Monster.createWeaponsVector(builder, weaps);
|
||||
MyGame.Sample.Monster.startPathVector(builder, 2);
|
||||
MyGame.Sample.Vec3.createVec3(builder, 1.0, 2.0, 3.0);
|
||||
MyGame.Sample.Vec3.createVec3(builder, 4.0, 5.0, 6.0);
|
||||
var path = builder.endVector();
|
||||
// Create our monster by using `startMonster()` and `endMonster()`.
|
||||
MyGame.Sample.Monster.startMonster(builder);
|
||||
MyGame.Sample.Monster.addPos(builder,
|
||||
MyGame.Sample.Vec3.createVec3(builder, 1.0, 2.0, 3.0));
|
||||
MyGame.Sample.Monster.addHp(builder, 300);
|
||||
MyGame.Sample.Monster.addColor(builder, MyGame.Sample.Color.Red)
|
||||
MyGame.Sample.Monster.addName(builder, name);
|
||||
MyGame.Sample.Monster.addInventory(builder, inv);
|
||||
MyGame.Sample.Monster.addWeapons(builder, weapons);
|
||||
MyGame.Sample.Monster.addEquippedType(builder,
|
||||
MyGame.Sample.Equipment.Weapon);
|
||||
MyGame.Sample.Monster.addEquipped(builder, axe);
|
||||
MyGame.Sample.Monster.addPath(builder, path);
|
||||
var orc = MyGame.Sample.Monster.endMonster(builder);
|
||||
MyGame.Sample.Monster.addEquippedType(builder,
|
||||
MyGame.Sample.Equipment.Weapon); // Union type
|
||||
MyGame.Sample.Monster.addEquipped(builder, axe); // Union data
|
||||
builder.finish(orc);
|
||||
|
||||
var buf = builder.asUint8Array(); // Of type `Uint8Array`.
|
||||
|
||||
console.log(buf);
|
||||
|
||||
fbsSocket.send(buf);
|
||||
}
|
||||
|
||||
let jsonSocket = new WebSocket("ws://localhost:1202/json");
|
||||
|
||||
jsonSocket.onopen = function () {
|
||||
sendJson();
|
||||
};
|
||||
|
||||
let sendJson = function () {
|
||||
let data = {
|
||||
a: 1,
|
||||
b: true,
|
||||
c: [1, 2, 3],
|
||||
d: {
|
||||
e: 1,
|
||||
}
|
||||
}
|
||||
jsonSocket.send(JSON.stringify(data));
|
||||
}
|
||||
+1
-1
@@ -13,7 +13,7 @@
|
||||
<dependency>
|
||||
<artifactId>flatbuffers-java</artifactId>
|
||||
<groupId>com.google.flatbuffers</groupId>
|
||||
<version>23.3.3</version>
|
||||
<version>1.12.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>netty-all</artifactId>
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Sample;
|
||||
|
||||
public final class Color {
|
||||
private Color() { }
|
||||
public static final byte Red = 0;
|
||||
public static final byte Green = 1;
|
||||
public static final byte Blue = 2;
|
||||
|
||||
public static final String[] names = { "Red", "Green", "Blue", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Sample;
|
||||
|
||||
public final class Equipment {
|
||||
private Equipment() { }
|
||||
public static final byte NONE = 0;
|
||||
public static final byte Weapon = 1;
|
||||
|
||||
public static final String[] names = { "NONE", "Weapon", };
|
||||
|
||||
public static String name(int e) { return names[e]; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Sample;
|
||||
|
||||
import java.nio.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
import com.google.flatbuffers.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Monster extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
|
||||
public static Monster getRootAsMonster(ByteBuffer _bb) { return getRootAsMonster(_bb, new Monster()); }
|
||||
public static Monster getRootAsMonster(ByteBuffer _bb, Monster obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Monster __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public MyGame.Sample.Vec3 pos() { return pos(new MyGame.Sample.Vec3()); }
|
||||
public MyGame.Sample.Vec3 pos(MyGame.Sample.Vec3 obj) { int o = __offset(4); return o != 0 ? obj.__assign(o + bb_pos, bb) : null; }
|
||||
public short mana() { int o = __offset(6); return o != 0 ? bb.getShort(o + bb_pos) : 150; }
|
||||
public short hp() { int o = __offset(8); return o != 0 ? bb.getShort(o + bb_pos) : 100; }
|
||||
public String name() { int o = __offset(10); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(10, 1); }
|
||||
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 10, 1); }
|
||||
public int inventory(int j) { int o = __offset(14); return o != 0 ? bb.get(__vector(o) + j * 1) & 0xFF : 0; }
|
||||
public int inventoryLength() { int o = __offset(14); return o != 0 ? __vector_len(o) : 0; }
|
||||
public ByteVector inventoryVector() { return inventoryVector(new ByteVector()); }
|
||||
public ByteVector inventoryVector(ByteVector obj) { int o = __offset(14); return o != 0 ? obj.__assign(__vector(o), bb) : null; }
|
||||
public ByteBuffer inventoryAsByteBuffer() { return __vector_as_bytebuffer(14, 1); }
|
||||
public ByteBuffer inventoryInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 14, 1); }
|
||||
public byte color() { int o = __offset(16); return o != 0 ? bb.get(o + bb_pos) : 2; }
|
||||
public MyGame.Sample.Weapon weapons(int j) { return weapons(new MyGame.Sample.Weapon(), j); }
|
||||
public MyGame.Sample.Weapon weapons(MyGame.Sample.Weapon obj, int j) { int o = __offset(18); return o != 0 ? obj.__assign(__indirect(__vector(o) + j * 4), bb) : null; }
|
||||
public int weaponsLength() { int o = __offset(18); return o != 0 ? __vector_len(o) : 0; }
|
||||
public MyGame.Sample.Weapon.Vector weaponsVector() { return weaponsVector(new MyGame.Sample.Weapon.Vector()); }
|
||||
public MyGame.Sample.Weapon.Vector weaponsVector(MyGame.Sample.Weapon.Vector obj) { int o = __offset(18); return o != 0 ? obj.__assign(__vector(o), 4, bb) : null; }
|
||||
public byte equippedType() { int o = __offset(20); return o != 0 ? bb.get(o + bb_pos) : 0; }
|
||||
public Table equipped(Table obj) { int o = __offset(22); return o != 0 ? __union(obj, o + bb_pos) : null; }
|
||||
public MyGame.Sample.Vec3 path(int j) { return path(new MyGame.Sample.Vec3(), j); }
|
||||
public MyGame.Sample.Vec3 path(MyGame.Sample.Vec3 obj, int j) { int o = __offset(24); return o != 0 ? obj.__assign(__vector(o) + j * 12, bb) : null; }
|
||||
public int pathLength() { int o = __offset(24); return o != 0 ? __vector_len(o) : 0; }
|
||||
public MyGame.Sample.Vec3.Vector pathVector() { return pathVector(new MyGame.Sample.Vec3.Vector()); }
|
||||
public MyGame.Sample.Vec3.Vector pathVector(MyGame.Sample.Vec3.Vector obj) { int o = __offset(24); return o != 0 ? obj.__assign(__vector(o), 12, bb) : null; }
|
||||
|
||||
public static void startMonster(FlatBufferBuilder builder) { builder.startTable(11); }
|
||||
public static void addPos(FlatBufferBuilder builder, int posOffset) { builder.addStruct(0, posOffset, 0); }
|
||||
public static void addMana(FlatBufferBuilder builder, short mana) { builder.addShort(1, mana, 150); }
|
||||
public static void addHp(FlatBufferBuilder builder, short hp) { builder.addShort(2, hp, 100); }
|
||||
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(3, nameOffset, 0); }
|
||||
public static void addInventory(FlatBufferBuilder builder, int inventoryOffset) { builder.addOffset(5, inventoryOffset, 0); }
|
||||
public static int createInventoryVector(FlatBufferBuilder builder, byte[] data) { return builder.createByteVector(data); }
|
||||
public static int createInventoryVector(FlatBufferBuilder builder, ByteBuffer data) { return builder.createByteVector(data); }
|
||||
public static void startInventoryVector(FlatBufferBuilder builder, int numElems) { builder.startVector(1, numElems, 1); }
|
||||
public static void addColor(FlatBufferBuilder builder, byte color) { builder.addByte(6, color, 2); }
|
||||
public static void addWeapons(FlatBufferBuilder builder, int weaponsOffset) { builder.addOffset(7, weaponsOffset, 0); }
|
||||
public static int createWeaponsVector(FlatBufferBuilder builder, int[] data) { builder.startVector(4, data.length, 4); for (int i = data.length - 1; i >= 0; i--) builder.addOffset(data[i]); return builder.endVector(); }
|
||||
public static void startWeaponsVector(FlatBufferBuilder builder, int numElems) { builder.startVector(4, numElems, 4); }
|
||||
public static void addEquippedType(FlatBufferBuilder builder, byte equippedType) { builder.addByte(8, equippedType, 0); }
|
||||
public static void addEquipped(FlatBufferBuilder builder, int equippedOffset) { builder.addOffset(9, equippedOffset, 0); }
|
||||
public static void addPath(FlatBufferBuilder builder, int pathOffset) { builder.addOffset(10, pathOffset, 0); }
|
||||
public static void startPathVector(FlatBufferBuilder builder, int numElems) { builder.startVector(12, numElems, 4); }
|
||||
public static int endMonster(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
return o;
|
||||
}
|
||||
public static void finishMonsterBuffer(FlatBufferBuilder builder, int offset) { builder.finish(offset); }
|
||||
public static void finishSizePrefixedMonsterBuffer(FlatBufferBuilder builder, int offset) { builder.finishSizePrefixed(offset); }
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Monster get(int j) { return get(new Monster(), j); }
|
||||
public Monster get(Monster obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Sample;
|
||||
|
||||
import java.nio.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
import com.google.flatbuffers.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Vec3 extends Struct {
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Vec3 __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public float x() { return bb.getFloat(bb_pos + 0); }
|
||||
public float y() { return bb.getFloat(bb_pos + 4); }
|
||||
public float z() { return bb.getFloat(bb_pos + 8); }
|
||||
|
||||
public static int createVec3(FlatBufferBuilder builder, float x, float y, float z) {
|
||||
builder.prep(4, 12);
|
||||
builder.putFloat(z);
|
||||
builder.putFloat(y);
|
||||
builder.putFloat(x);
|
||||
return builder.offset();
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Vec3 get(int j) { return get(new Vec3(), j); }
|
||||
public Vec3 get(Vec3 obj, int j) { return obj.__assign(__element(j), bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// automatically generated by the FlatBuffers compiler, do not modify
|
||||
|
||||
package MyGame.Sample;
|
||||
|
||||
import java.nio.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
import com.google.flatbuffers.*;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public final class Weapon extends Table {
|
||||
public static void ValidateVersion() { Constants.FLATBUFFERS_1_12_0(); }
|
||||
public static Weapon getRootAsWeapon(ByteBuffer _bb) { return getRootAsWeapon(_bb, new Weapon()); }
|
||||
public static Weapon getRootAsWeapon(ByteBuffer _bb, Weapon obj) { _bb.order(ByteOrder.LITTLE_ENDIAN); return (obj.__assign(_bb.getInt(_bb.position()) + _bb.position(), _bb)); }
|
||||
public void __init(int _i, ByteBuffer _bb) { __reset(_i, _bb); }
|
||||
public Weapon __assign(int _i, ByteBuffer _bb) { __init(_i, _bb); return this; }
|
||||
|
||||
public String name() { int o = __offset(4); return o != 0 ? __string(o + bb_pos) : null; }
|
||||
public ByteBuffer nameAsByteBuffer() { return __vector_as_bytebuffer(4, 1); }
|
||||
public ByteBuffer nameInByteBuffer(ByteBuffer _bb) { return __vector_in_bytebuffer(_bb, 4, 1); }
|
||||
public short damage() { int o = __offset(6); return o != 0 ? bb.getShort(o + bb_pos) : 0; }
|
||||
|
||||
public static int createWeapon(FlatBufferBuilder builder,
|
||||
int nameOffset,
|
||||
short damage) {
|
||||
builder.startTable(2);
|
||||
Weapon.addName(builder, nameOffset);
|
||||
Weapon.addDamage(builder, damage);
|
||||
return Weapon.endWeapon(builder);
|
||||
}
|
||||
|
||||
public static void startWeapon(FlatBufferBuilder builder) { builder.startTable(2); }
|
||||
public static void addName(FlatBufferBuilder builder, int nameOffset) { builder.addOffset(0, nameOffset, 0); }
|
||||
public static void addDamage(FlatBufferBuilder builder, short damage) { builder.addShort(1, damage, 0); }
|
||||
public static int endWeapon(FlatBufferBuilder builder) {
|
||||
int o = builder.endTable();
|
||||
return o;
|
||||
}
|
||||
|
||||
public static final class Vector extends BaseVector {
|
||||
public Vector __assign(int _vector, int _element_size, ByteBuffer _bb) { __reset(_vector, _element_size, _bb); return this; }
|
||||
|
||||
public Weapon get(int j) { return get(new Weapon(), j); }
|
||||
public Weapon get(Weapon obj, int j) { return obj.__assign(__indirect(__element(j), bb), bb); }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,73 @@
|
||||
package com.miti99.netty;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.epoll.Epoll;
|
||||
import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||
import io.netty.handler.codec.http.HttpServerCodec;
|
||||
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler;
|
||||
import io.netty.handler.codec.http.websocketx.extensions.compression.WebSocketServerCompressionHandler;
|
||||
import io.netty.handler.logging.LogLevel;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
import io.netty.util.internal.logging.Slf4JLoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import lombok.val;
|
||||
|
||||
@Slf4j
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
log.debug("debug");
|
||||
log.info("info");
|
||||
log.warn("warn");
|
||||
log.error("error");
|
||||
InternalLoggerFactory.setDefaultFactory(Slf4JLoggerFactory.INSTANCE);
|
||||
var parentGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup();
|
||||
var childGroup = Epoll.isAvailable() ? new EpollEventLoopGroup() : new NioEventLoopGroup();
|
||||
|
||||
val serverBootstrap = new ServerBootstrap();
|
||||
serverBootstrap.group(parentGroup, childGroup).channel(
|
||||
NioServerSocketChannel.class
|
||||
).handler(new LoggingHandler(LogLevel.DEBUG))
|
||||
.childHandler(new ChannelInitializer<>() {
|
||||
|
||||
@Override
|
||||
protected void initChannel(Channel channel) {
|
||||
channel.pipeline()
|
||||
.addLast(new LoggingHandler(LogLevel.DEBUG))
|
||||
.addLast(new HttpServerCodec())
|
||||
.addLast(new HttpObjectAggregator(65536))
|
||||
.addLast(new WebSocketServerCompressionHandler())
|
||||
.addLast(new WebSocketServerProtocolHandler("/fbs", null, true))
|
||||
.addLast(new WebsocketDecoder())
|
||||
.addLast(new WebsocketHandler());
|
||||
}
|
||||
})
|
||||
.childHandler(
|
||||
new ChannelInitializer<>() {
|
||||
|
||||
@Override
|
||||
protected void initChannel(Channel channel) {
|
||||
channel.pipeline()
|
||||
.addLast(new LoggingHandler(LogLevel.INFO))
|
||||
.addLast(new HttpServerCodec())
|
||||
.addLast(new HttpObjectAggregator(65536))
|
||||
.addLast(new WebSocketServerCompressionHandler())
|
||||
.addLast(new WebSocketServerProtocolHandler("/json", null, true))
|
||||
.addLast(new WebsocketHandler());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
try {
|
||||
val channelFuture = serverBootstrap.bind(1202).sync();
|
||||
channelFuture.channel().closeFuture().sync();
|
||||
} catch (InterruptedException interruptedException) {
|
||||
log.error("Interrupted", interruptedException);
|
||||
} finally {
|
||||
parentGroup.shutdownGracefully();
|
||||
childGroup.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.miti99.netty;
|
||||
|
||||
import MyGame.Sample.Monster;
|
||||
import io.netty.buffer.ByteBufUtil;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class WebsocketDecoder extends MessageToMessageDecoder<BinaryWebSocketFrame> {
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext channelHandlerContext,
|
||||
BinaryWebSocketFrame binaryWebSocketFrame, List<Object> list) {
|
||||
var byteBuf = binaryWebSocketFrame.content();
|
||||
byteBuf.retain();
|
||||
|
||||
var bytes = ByteBufUtil.getBytes(byteBuf);
|
||||
|
||||
log.info(Arrays.toString(bytes));
|
||||
|
||||
var byteBuffer = ByteBuffer.wrap(bytes);
|
||||
|
||||
var monster = Monster.getRootAsMonster(byteBuffer);
|
||||
|
||||
list.add(monster);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.miti99.netty;
|
||||
|
||||
|
||||
|
||||
import MyGame.Sample.Equipment;
|
||||
import MyGame.Sample.Monster;
|
||||
import MyGame.Sample.Weapon;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.ChannelInboundHandlerAdapter;
|
||||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@ChannelHandler.Sharable
|
||||
@Slf4j
|
||||
public class WebsocketHandler extends ChannelInboundHandlerAdapter {
|
||||
|
||||
@Override
|
||||
public void channelRead(ChannelHandlerContext ctx, Object msg) {
|
||||
if (msg instanceof Monster monster) {
|
||||
var hp = monster.hp();
|
||||
var mana = monster.mana();
|
||||
var name = monster.name();
|
||||
|
||||
log.info("hp : {}, mana : {}, name : {}", hp, mana, name);
|
||||
|
||||
var pos = monster.pos();
|
||||
var x = pos.x();
|
||||
var y = pos.y();
|
||||
var z = pos.z();
|
||||
|
||||
log.info("x : {}, y : {}, z : {}", x, y, z);
|
||||
|
||||
var invLength = monster.inventoryLength();
|
||||
var thirdItem = monster.inventory(2);
|
||||
|
||||
var weaponsLength = monster.weaponsLength();
|
||||
var secondWeaponName = monster.weapons(1).name();
|
||||
var secondWeaponDamage = monster.weapons(1).damage();
|
||||
|
||||
log.info(
|
||||
"invLength : {}, thirdItem : {}, weaponsLength : {}, secondWeaponName : {}, secondWeaponDamage : {}",
|
||||
invLength, thirdItem, weaponsLength, secondWeaponName, secondWeaponDamage);
|
||||
|
||||
var unionType = monster.equippedType();
|
||||
|
||||
if (unionType == Equipment.Weapon) {
|
||||
var weapon = (Weapon) monster.equipped(new Weapon());
|
||||
|
||||
var weaponName = weapon.name(); // "Axe"
|
||||
var weaponDamage = weapon.damage(); // 5
|
||||
|
||||
log.info("weaponName : {}, weaponDamage : {}", weaponName, weaponDamage);
|
||||
}
|
||||
} else if (msg instanceof TextWebSocketFrame textWebSocketFrame) {
|
||||
log.info(textWebSocketFrame.text());
|
||||
}else {
|
||||
ctx.fireChannelRead(msg);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
|
||||
super.channelReadComplete(ctx);
|
||||
ctx.flush();
|
||||
}
|
||||
}
|
||||
@@ -40,12 +40,14 @@
|
||||
<import class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"/>
|
||||
<import class="ch.qos.logback.core.ConsoleAppender"/>
|
||||
|
||||
<logger name="com.miti99.netty">
|
||||
<appender-ref ref="Console"/>
|
||||
<appender-ref ref="Info"/>
|
||||
</logger>
|
||||
<!-- <logger name="com.miti99.netty">-->
|
||||
<!-- <appender-ref ref="Console"/>-->
|
||||
<!-- <appender-ref ref="Info"/>-->
|
||||
<!-- </logger>-->
|
||||
|
||||
<root>
|
||||
<appender-ref ref="Console"/>
|
||||
<appender-ref ref="Info"/>
|
||||
<appender-ref ref="Error"/>
|
||||
</root>
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
// Example IDL file for our monster's schema.
|
||||
|
||||
namespace MyGame.Sample;
|
||||
|
||||
enum Color:byte { Red = 0, Green, Blue = 2 }
|
||||
|
||||
union Equipment { Weapon } // Optionally add more tables.
|
||||
|
||||
struct Vec3 {
|
||||
x:float;
|
||||
y:float;
|
||||
z:float;
|
||||
}
|
||||
|
||||
table Monster {
|
||||
pos:Vec3; // Struct.
|
||||
mana:short = 150;
|
||||
hp:short = 100;
|
||||
name:string;
|
||||
friendly:bool = false (deprecated);
|
||||
inventory:[ubyte]; // Vector of scalars.
|
||||
color:Color = Blue; // Enum.
|
||||
weapons:[Weapon]; // Vector of tables.
|
||||
equipped:Equipment; // Union.
|
||||
path:[Vec3]; // Vector of structs.
|
||||
}
|
||||
|
||||
table Weapon {
|
||||
name:string;
|
||||
damage:short;
|
||||
}
|
||||
|
||||
root_type Monster;
|
||||
Reference in New Issue
Block a user