(accessor: string)
| 34 | } |
| 35 | |
| 36 | write(accessor: string): string { |
| 37 | const codec = this.builder.getExternal(DecimalCodec.name); |
| 38 | const scale = this.scope.uniqueName("decimal_scale"); |
| 39 | const unscaled = this.scope.uniqueName("decimal_unscaled"); |
| 40 | const magnitudeBytes = this.scope.uniqueName("decimal_magnitude_bytes"); |
| 41 | const meta = this.scope.uniqueName("decimal_meta"); |
| 42 | return ` |
| 43 | const ${scale} = ${accessor}.scale; |
| 44 | const ${unscaled} = ${accessor}.unscaledValue; |
| 45 | ${this.builder.writer.writeVarInt32(scale)} |
| 46 | if (${codec}.canUseSmallEncoding(${unscaled})) { |
| 47 | ${this.builder.writer.writeVarUInt64(`(${codec}.encodeZigZag64(${unscaled}) << 1n)`)} |
| 48 | } else { |
| 49 | const ${magnitudeBytes} = ${codec}.toCanonicalLittleEndianMagnitude(${unscaled}); |
| 50 | const ${meta} = (BigInt(${magnitudeBytes}.length) << 1n) | (${unscaled} < 0n ? 1n : 0n); |
| 51 | ${this.builder.writer.writeVarUInt64(`((${meta} << 1n) | 1n)`)} |
| 52 | ${this.builder.writer.buffer(magnitudeBytes)} |
| 53 | } |
| 54 | `; |
| 55 | } |
| 56 | |
| 57 | read(accessor: (expr: string) => string): string { |
| 58 | const codec = this.builder.getExternal(DecimalCodec.name); |
nothing calls this directly
no test coverage detected