* Serializes this instance into the provided serializer context. * @template {object} T * @param {T} obj plain object * @param {import("./ObjectMiddleware").ObjectSerializerContext<((keyof T)[] | keyof T | null | T[keyof T])[]>} context context
(obj, context)
| 78 | * @param {import("./ObjectMiddleware").ObjectSerializerContext<((keyof T)[] | keyof T | null | T[keyof T])[]>} context context |
| 79 | */ |
| 80 | serialize(obj, context) { |
| 81 | const keys = /** @type {(keyof T)[]} */ (Object.keys(obj)); |
| 82 | if (keys.length > 128) { |
| 83 | // Objects with so many keys are unlikely to share structure |
| 84 | // with other objects |
| 85 | context.write(keys); |
| 86 | for (const key of keys) { |
| 87 | context.write(obj[key]); |
| 88 | } |
| 89 | } else if (keys.length > 1) { |
| 90 | context.write(getCachedKeys(keys, context.write)); |
| 91 | for (const key of keys) { |
| 92 | context.write(obj[key]); |
| 93 | } |
| 94 | } else if (keys.length === 1) { |
| 95 | const key = keys[0]; |
| 96 | context.write(key); |
| 97 | context.write(obj[key]); |
| 98 | } else { |
| 99 | context.write(null); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Restores this instance from the provided deserializer context. |
nothing calls this directly
no test coverage detected