/** * Jackson doesn't have native support for timestamp. As per the RFC 7049 * (https://tools.ietf.org/html/rfc7049#section-2.4.1) we will need to * write a tag and write the epoch. */ @Override public StructuredJsonGenerator writeValue(Date date, TimestampFormat timestampFormat) { if (!(getGenerator() instanceof CBORGenerator)) { throw new IllegalStateException("SdkCborGenerator is not created with a CBORGenerator."); } CBORGenerator generator = (CBORGenerator) getGenerator(); try { generator.writeTag(CBOR_TAG_TIMESTAP); generator.writeNumber(date.getTime()); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
/** * Jackson doesn't have native support for timestamp. As per the RFC 7049 * (https://tools.ietf.org/html/rfc7049#section-2.4.1) we will need to * write a tag and write the epoch. */ @Override public StructuredJsonGenerator writeValue(Date date, TimestampFormat timestampFormat) { if (!(getGenerator() instanceof CBORGenerator)) { throw new IllegalStateException("SdkCborGenerator is not created with a CBORGenerator."); } CBORGenerator generator = (CBORGenerator) getGenerator(); try { generator.writeTag(CBOR_TAG_TIMESTAP); generator.writeNumber(date.getTime()); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
@Override public void writeNumber(long l) throws IOException { if (_cfgMinimalInts) { // First: maybe 32 bits is enough? if (l <= MAX_INT_AS_LONG && l >= MIN_INT_AS_LONG) { writeNumber((int) l); return; } } _verifyValueWrite("write number"); _ensureRoomForOutput(9); if (l < 0L) { l += 1; l = -l; _outputBuffer[_outputTail++] = (PREFIX_TYPE_INT_NEG + SUFFIX_UINT64_ELEMENTS); } else { _outputBuffer[_outputTail++] = (PREFIX_TYPE_INT_POS + SUFFIX_UINT64_ELEMENTS); } int i = (int) (l >> 32); _outputBuffer[_outputTail++] = (byte) (i >> 24); _outputBuffer[_outputTail++] = (byte) (i >> 16); _outputBuffer[_outputTail++] = (byte) (i >> 8); _outputBuffer[_outputTail++] = (byte) i; i = (int) l; _outputBuffer[_outputTail++] = (byte) (i >> 24); _outputBuffer[_outputTail++] = (byte) (i >> 16); _outputBuffer[_outputTail++] = (byte) (i >> 8); _outputBuffer[_outputTail++] = (byte) i; }
/** * Jackson doesn't have native support for timestamp. As per the RFC 7049 * (https://tools.ietf.org/html/rfc7049#section-2.4.1) we will need to * write a tag and write the epoch. */ @Override public StructuredJsonGenerator writeValue(Instant instant) { if (!(getGenerator() instanceof CBORGenerator)) { throw new IllegalStateException("SdkCborGenerator is not created with a CBORGenerator."); } CBORGenerator generator = (CBORGenerator) getGenerator(); try { generator.writeTag(CBOR_TAG_TIMESTAMP); generator.writeNumber(instant.toEpochMilli()); } catch (IOException e) { throw new JsonGenerationException(e); } return this; } }
@Override public void writeNumber(long l) throws IOException { if (_cfgMinimalInts) { // First: maybe 32 bits is enough? if (l <= MAX_INT_AS_LONG && l >= MIN_INT_AS_LONG) { writeNumber((int) l); return; } } _verifyValueWrite("write number"); _ensureRoomForOutput(9); if (l < 0L) { l += 1; l = -l; _outputBuffer[_outputTail++] = (PREFIX_TYPE_INT_NEG + 27); } else { _outputBuffer[_outputTail++] = (PREFIX_TYPE_INT_POS + 27); } int i = (int) (l >> 32); _outputBuffer[_outputTail++] = (byte) (i >> 24); _outputBuffer[_outputTail++] = (byte) (i >> 16); _outputBuffer[_outputTail++] = (byte) (i >> 8); _outputBuffer[_outputTail++] = (byte) i; i = (int) l; _outputBuffer[_outputTail++] = (byte) (i >> 24); _outputBuffer[_outputTail++] = (byte) (i >> 16); _outputBuffer[_outputTail++] = (byte) (i >> 8); _outputBuffer[_outputTail++] = (byte) i; }
/** * Jackson doesn't have native support for timestamp. As per the RFC 7049 * (https://tools.ietf.org/html/rfc7049#section-2.4.1) we will need to * write a tag and write the epoch. */ @Override public StructuredJsonGenerator writeValue(Date date) { if (!(getGenerator() instanceof CBORGenerator)) { throw new IllegalStateException("SdkCborGenerator is not created with a CBORGenerator."); } CBORGenerator generator = (CBORGenerator) getGenerator(); try { generator.writeTag(CBOR_TAG_TIMESTAP); generator.writeNumber(date.getTime()); } catch (IOException e) { throw new JsonGenerationException(e); } return this; }
/** * Jackson doesn't have native support for timestamp. As per the RFC 7049 * (https://tools.ietf.org/html/rfc7049#section-2.4.1) we will need to * write a tag and write the epoch. */ @Override public StructuredJsonGenerator writeValue(Instant instant) { if (!(getGenerator() instanceof CBORGenerator)) { throw new IllegalStateException("SdkCborGenerator is not created with a CBORGenerator."); } CBORGenerator generator = (CBORGenerator) getGenerator(); try { generator.writeTag(CBOR_TAG_TIMESTAMP); generator.writeNumber(instant.toEpochMilli()); } catch (IOException e) { throw new JsonGenerationException(e); } return this; } }
@Override public void writeNumber(long l) throws IOException { if (_cfgMinimalInts) { // First: maybe 32 bits is enough? if (l <= MAX_INT_AS_LONG && l >= MIN_INT_AS_LONG) { writeNumber((int) l); return; } } _verifyValueWrite("write number"); _ensureRoomForOutput(9); if (l < 0L) { l += 1; l = -l; _outputBuffer[_outputTail++] = (PREFIX_TYPE_INT_NEG + 27); } else { _outputBuffer[_outputTail++] = (PREFIX_TYPE_INT_POS + 27); } int i = (int) (l >> 32); _outputBuffer[_outputTail++] = (byte) (i >> 24); _outputBuffer[_outputTail++] = (byte) (i >> 16); _outputBuffer[_outputTail++] = (byte) (i >> 8); _outputBuffer[_outputTail++] = (byte) i; i = (int) l; _outputBuffer[_outputTail++] = (byte) (i >> 24); _outputBuffer[_outputTail++] = (byte) (i >> 16); _outputBuffer[_outputTail++] = (byte) (i >> 8); _outputBuffer[_outputTail++] = (byte) i; }