32
32
public class Frame implements Payload
33
33
{
34
34
public static final ByteBuffer NULL_BYTEBUFFER = FrameHeaderFlyweight .NULL_BYTEBUFFER ;
35
+ public static final int DATA_MTU = 32 * 1024 ;
36
+ public static final int METADATA_MTU = 32 * 1024 ;
35
37
36
38
/*
37
39
* ThreadLocal handling in the pool itself. We don't have a per thread pool at this level.
@@ -138,6 +140,16 @@ public int length()
138
140
return length ;
139
141
}
140
142
143
+ /**
144
+ * Return the flags field for the frame
145
+ *
146
+ * @return frame flags field value
147
+ */
148
+ public int flags ()
149
+ {
150
+ return FrameHeaderFlyweight .flags (directBuffer , offset );
151
+ }
152
+
141
153
/**
142
154
* Mutates this Frame to contain the given ByteBuffer
143
155
*
@@ -224,7 +236,7 @@ public void wrap(final int streamId, final FrameType type, final ByteBuffer data
224
236
this .directBuffer =
225
237
POOL .acquireMutableDirectBuffer (FrameHeaderFlyweight .computeFrameHeaderLength (type , 0 , data .capacity ()));
226
238
227
- this .length = FrameHeaderFlyweight .encode (this .directBuffer , offset , streamId , type , NULL_BYTEBUFFER , data );
239
+ this .length = FrameHeaderFlyweight .encode (this .directBuffer , offset , streamId , 0 , type , NULL_BYTEBUFFER , data );
228
240
}
229
241
230
242
/* TODO:
@@ -389,11 +401,11 @@ public static Frame from(int streamId, FrameType type, Payload payload, int init
389
401
390
402
if (type .hasInitialRequestN ())
391
403
{
392
- frame .length = RequestFrameFlyweight .encode (frame .directBuffer , frame .offset , streamId , type , initialRequestN , md , d );
404
+ frame .length = RequestFrameFlyweight .encode (frame .directBuffer , frame .offset , streamId , 0 , type , initialRequestN , md , d );
393
405
}
394
406
else
395
407
{
396
- frame .length = RequestFrameFlyweight .encode (frame .directBuffer , frame .offset , streamId , type , md , d );
408
+ frame .length = RequestFrameFlyweight .encode (frame .directBuffer , frame .offset , streamId , 0 , type , md , d );
397
409
}
398
410
399
411
return frame ;
@@ -403,10 +415,19 @@ public static Frame from(int streamId, FrameType type, int flags)
403
415
{
404
416
final Frame frame = POOL .acquireFrame (RequestFrameFlyweight .computeFrameLength (type , 0 , 0 ));
405
417
406
- frame .length = RequestFrameFlyweight .encode (frame .directBuffer , frame .offset , streamId , type , flags );
418
+ frame .length = RequestFrameFlyweight .encode (frame .directBuffer , frame .offset , streamId , flags , type , NULL_BYTEBUFFER , NULL_BYTEBUFFER );
407
419
return frame ;
408
420
}
409
421
422
+ public static Frame from (int streamId , FrameType type , ByteBuffer metadata , ByteBuffer data , int initialRequestN , int flags )
423
+ {
424
+ final Frame frame = POOL .acquireFrame (RequestFrameFlyweight .computeFrameLength (type , metadata .capacity (), data .capacity ()));
425
+
426
+ frame .length = RequestFrameFlyweight .encode (frame .directBuffer , frame .offset , streamId , flags , type , initialRequestN , NULL_BYTEBUFFER , NULL_BYTEBUFFER );
427
+ return frame ;
428
+
429
+ }
430
+
410
431
public static long initialRequestN (final Frame frame )
411
432
{
412
433
final FrameType type = frame .getType ();
@@ -452,7 +473,16 @@ public static Frame from(int streamId, FrameType type, Payload payload)
452
473
final Frame frame =
453
474
POOL .acquireFrame (FrameHeaderFlyweight .computeFrameHeaderLength (type , metadata .capacity (), data .capacity ()));
454
475
455
- frame .length = FrameHeaderFlyweight .encode (frame .directBuffer , frame .offset , streamId , type , metadata , data );
476
+ frame .length = FrameHeaderFlyweight .encode (frame .directBuffer , frame .offset , streamId , 0 , type , metadata , data );
477
+ return frame ;
478
+ }
479
+
480
+ public static Frame from (int streamId , FrameType type , ByteBuffer metadata , ByteBuffer data , int flags )
481
+ {
482
+ final Frame frame =
483
+ POOL .acquireFrame (FrameHeaderFlyweight .computeFrameHeaderLength (type , metadata .capacity (), data .capacity ()));
484
+
485
+ frame .length = FrameHeaderFlyweight .encode (frame .directBuffer , frame .offset , streamId , flags , type , metadata , data );
456
486
return frame ;
457
487
}
458
488
@@ -462,7 +492,7 @@ public static Frame from(int streamId, FrameType type)
462
492
POOL .acquireFrame (FrameHeaderFlyweight .computeFrameHeaderLength (type , 0 , 0 ));
463
493
464
494
frame .length = FrameHeaderFlyweight .encode (
465
- frame .directBuffer , frame .offset , streamId , type , Frame .NULL_BYTEBUFFER , Frame .NULL_BYTEBUFFER );
495
+ frame .directBuffer , frame .offset , streamId , 0 , type , Frame .NULL_BYTEBUFFER , Frame .NULL_BYTEBUFFER );
466
496
return frame ;
467
497
}
468
498
}
@@ -475,7 +505,7 @@ public static Frame from(int streamId)
475
505
POOL .acquireFrame (FrameHeaderFlyweight .computeFrameHeaderLength (FrameType .CANCEL , 0 , 0 ));
476
506
477
507
frame .length = FrameHeaderFlyweight .encode (
478
- frame .directBuffer , frame .offset , streamId , FrameType .CANCEL , Frame .NULL_BYTEBUFFER , Frame .NULL_BYTEBUFFER );
508
+ frame .directBuffer , frame .offset , streamId , 0 , FrameType .CANCEL , Frame .NULL_BYTEBUFFER , Frame .NULL_BYTEBUFFER );
479
509
return frame ;
480
510
}
481
511
}
@@ -490,7 +520,7 @@ public static Frame from(ByteBuffer data, boolean respond)
490
520
final int flags = (respond ? FrameHeaderFlyweight .FLAGS_KEEPALIVE_R : 0 );
491
521
492
522
frame .length = FrameHeaderFlyweight .encode (
493
- frame .directBuffer , frame .offset , flags , FrameType .KEEPALIVE , Frame .NULL_BYTEBUFFER , data );
523
+ frame .directBuffer , frame .offset , 0 , flags , FrameType .KEEPALIVE , Frame .NULL_BYTEBUFFER , data );
494
524
495
525
return frame ;
496
526
}
0 commit comments