@@ -36,6 +36,7 @@ class Packet implements IDatabaseObject, JsonSerializable
36
36
37
37
// Maximum SQL field lengths, alter as appropriate
38
38
const MAX_APPLICATION_LAYER_ID = 0x7FFFFFFFFFFFFFFF ;
39
+ const MAX_BRIEF = 191 ;
39
40
const MAX_DIRECTION = 0x7FFFFFFFFFFFFFFF ;
40
41
const MAX_EDITED_COUNT = 0x7FFFFFFFFFFFFFFF ;
41
42
const MAX_FORMAT = 0xFFFF ;
@@ -57,6 +58,7 @@ class Packet implements IDatabaseObject, JsonSerializable
57
58
private $ _id ;
58
59
59
60
protected $ application_layer_id ;
61
+ protected $ brief ;
60
62
protected $ created_datetime ;
61
63
protected $ direction ;
62
64
protected $ edited_count ;
@@ -110,6 +112,7 @@ public function allocate()
110
112
}
111
113
112
114
$ this ->setApplicationLayerId (self ::DEFAULT_APPLICATION_LAYER_ID );
115
+ $ this ->setBrief ('' );
113
116
$ this ->setCreatedDateTime (new DateTime ('now ' ));
114
117
$ this ->setDirection (self ::DEFAULT_DIRECTION );
115
118
$ this ->setEditedCount (0 );
@@ -136,6 +139,7 @@ public function allocate()
136
139
`id`,
137
140
`options_bitmask`,
138
141
`packet_application_layer_id`,
142
+ `packet_brief`,
139
143
`packet_direction_id`,
140
144
`packet_format`,
141
145
`packet_id`,
@@ -188,6 +192,7 @@ protected function allocateObject(StdClass $value)
188
192
$ tz = new DateTimeZone (self ::TZ_SQL );
189
193
190
194
$ this ->setApplicationLayerId ($ value ->packet_application_layer_id );
195
+ $ this ->setBrief ($ value ->packet_brief );
191
196
$ this ->setCreatedDateTime (new DateTime ($ value ->created_datetime , $ tz ));
192
197
$ this ->setDirection ($ value ->packet_direction_id );
193
198
$ this ->setEditedCount ($ value ->edited_count );
@@ -223,6 +228,7 @@ public function commit()
223
228
`id`,
224
229
`options_bitmask`,
225
230
`packet_application_layer_id`,
231
+ `packet_brief`,
226
232
`packet_direction_id`,
227
233
`packet_format`,
228
234
`packet_id`,
@@ -231,14 +237,15 @@ public function commit()
231
237
`packet_transport_layer_id`,
232
238
`user_id`
233
239
) VALUES (
234
- :c_dt, :e_c, :e_dt, :id, :opts, :app_id, :d, :f, :pid, :n, :r, :tr_id, :uid
240
+ :c_dt, :e_c, :e_dt, :id, :opts, :app_id, :b, : d, :f, :pid, :n, :r, :tr_id, :uid
235
241
) ON DUPLICATE KEY UPDATE
236
242
`created_datetime` = :c_dt,
237
243
`edited_count` = :e_c,
238
244
`edited_datetime` = :e_dt,
239
245
`id` = :id,
240
246
`options_bitmask` = :opts,
241
247
`packet_application_layer_id` = :app_id,
248
+ `packet_brief` = :b,
242
249
`packet_direction_id` = :d,
243
250
`packet_format` = :f,
244
251
`packet_id` = :pid,
@@ -255,6 +262,7 @@ public function commit()
255
262
);
256
263
257
264
$ q ->bindParam (':app_id ' , $ this ->application_layer_id , PDO ::PARAM_INT );
265
+ $ q ->bindParam (':b ' , $ this ->brief , (is_null ($ this ->brief ) ? PDO ::PARAM_NULL : PDO ::PARAM_STR ));
258
266
$ q ->bindParam (':c_dt ' , $ created_datetime , PDO ::PARAM_STR );
259
267
$ q ->bindParam (':d ' , $ this ->direction , PDO ::PARAM_INT );
260
268
$ q ->bindParam (':e_c ' , $ this ->edited_count , PDO ::PARAM_INT );
@@ -389,6 +397,17 @@ public function getApplicationLayerId()
389
397
return $ this ->application_layer_id ;
390
398
}
391
399
400
+ public function getBrief (bool $ format )
401
+ {
402
+ if (!($ format && $ this ->getOption (self ::OPTION_MARKDOWN )))
403
+ {
404
+ return $ this ->brief ;
405
+ }
406
+
407
+ $ md = new Parsedown ();
408
+ return $ md ->text ($ this ->brief );
409
+ }
410
+
392
411
public function getCreatedDateTime ()
393
412
{
394
413
return $ this ->created_datetime ;
@@ -626,6 +645,7 @@ public function jsonSerialize()
626
645
'id ' => $ this ->getId (),
627
646
'options_bitmask ' => $ this ->getOptions (),
628
647
'packet_application_layer_id ' => $ this ->getApplicationLayerId (),
648
+ 'packet_brief ' => $ this ->getBrief (false ),
629
649
'packet_direction_id ' => $ this ->getDirection (),
630
650
'packet_format ' => $ this ->getFormat (),
631
651
'packet_id ' => $ this ->getPacketId (),
@@ -653,6 +673,23 @@ public function setApplicationLayerId(int $value)
653
673
$ this ->application_layer_id = $ value ;
654
674
}
655
675
676
+ /**
677
+ * Sets the brief description of this packet.
678
+ *
679
+ * @param string $value The brief description.
680
+ */
681
+ public function setBrief (string $ value )
682
+ {
683
+ if (strlen ($ value ) > self ::MAX_BRIEF )
684
+ {
685
+ throw new OutOfBoundsException (sprintf (
686
+ 'value must be between 0-%d characters ' , self ::MAX_BRIEF
687
+ ));
688
+ }
689
+
690
+ $ this ->brief = $ value ;
691
+ }
692
+
656
693
/**
657
694
* Sets the Date and Time this Packet was created.
658
695
*
0 commit comments