1 /*
2 * Logback: the reliable, generic, fast and flexible logging framework.
3 * Copyright (C) 1999-2026, QOS.ch. All rights reserved.
4 *
5 * This program and the accompanying materials are dual-licensed under
6 * either the terms of the Eclipse Public License v2.0 as published by
7 * the Eclipse Foundation
8 *
9 * or (per the licensee's choosing)
10 *
11 * under the terms of the GNU Lesser General Public License version 2.1
12 * as published by the Free Software Foundation.
13 */
14 package ch.qos.logback.core.kryo;
15
16 public class KryoCoreConstants {
17
18 static public boolean NEW_ENTRY = true;
19 static public boolean CACHED_ENTRY = false;
20
21 /**
22 * Sentinel id written on the wire (as 0 in the id field) when a value is not
23 * registered in the id map (e.g. frequency-gated first sightings).
24 */
25 static public int UNREGISTERED_ID = -1;
26
27 /**
28 * Maximum id that may appear in a {@link SerializerBase} entry header (12-bit field).
29 * Ids are assigned starting at 1; {@link #UNREGISTERED_ID} is encoded as 0.
30 */
31 static public final int MAX_SERIALIZER_ID = 0xFFF; // 4095
32
33 /**
34 * Live size of a {@link BidirectionalObjectToIdMap}: at least 1, at most
35 * {@link #MAX_SERIALIZER_ID} so LRU cannot mint an id outside the 12-bit header.
36 */
37 public static int cappedSerializerCapacity(int capacity) {
38 if (capacity < 1) {
39 return 1;
40 }
41 return Math.min(capacity, MAX_SERIALIZER_ID);
42 }
43
44 /**
45 * 2-byte entry header layout (big-endian short):
46 * <pre>
47 * bits 15-3: 13-bit data
48 * bit 12 of data (bit 15 of short): 1 = NEW_ENTRY, 0 = CACHED_ENTRY
49 * bits 0-11 of data (bits 14-3 of short): id; 0 means UNREGISTERED_ID on NEW only
50 * bits 2-0: 3-bit CRC over the 13 data bits (poly x^3+x+1)
51 * </pre>
52 */
53 static public final int ENTRY_HEADER_DATA_BITS = 13;
54 static public final int ENTRY_HEADER_CRC_BITS = 3;
55 static public final int ENTRY_HEADER_CRC_MASK = 0x7;
56 static public final int ENTRY_HEADER_DATA_MASK = 0x1FFF;
57
58 /** Within the 13-bit data word: NEW_ENTRY flag. */
59 static public final int ENTRY_HEADER_NEW_FLAG = 1 << 12;
60
61 /** Within the 13-bit data word: 12-bit id mask. */
62 static public final int ENTRY_HEADER_ID_MASK = 0xFFF;
63
64 /**
65 * CRC-3 generator polynomial {@code x^3 + x + 1} (0b1011), used over the 13 data bits.
66 */
67 static public final int ENTRY_HEADER_CRC3_POLY = 0b1011;
68
69 static public final String KRYO_UNSAFE_PROPERTY_KEY = "kryo.unsafe";
70 }