Java Code Examples for com.dslplatform.json.JsonWriter#writeByte()
The following examples show how to use
com.dslplatform.json.JsonWriter#writeByte() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MetricRegistrySerializer.java From apm-agent-java with Apache License 2.0 | 6 votes |
static void serializeMetricSet(MetricSet metricSet, long epochMicros, StringBuilder replaceBuilder, JsonWriter jw) { jw.writeByte(JsonWriter.OBJECT_START); { DslJsonSerializer.writeFieldName("metricset", jw); jw.writeByte(JsonWriter.OBJECT_START); { DslJsonSerializer.writeFieldName("timestamp", jw); NumberConverter.serialize(epochMicros, jw); jw.writeByte(JsonWriter.COMMA); DslJsonSerializer.serializeLabels(metricSet.getLabels(), replaceBuilder, jw); DslJsonSerializer.writeFieldName("samples", jw); jw.writeByte(JsonWriter.OBJECT_START); boolean hasSamples = serializeGauges(metricSet.getGauges(), jw); hasSamples |= serializeTimers(metricSet.getTimers(), hasSamples, jw); serializeCounters(metricSet.getCounters(), hasSamples, jw); jw.writeByte(JsonWriter.OBJECT_END); } jw.writeByte(JsonWriter.OBJECT_END); } jw.writeByte(JsonWriter.OBJECT_END); }
Example 2
Source File: WriteDescription.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 6 votes |
public final void write(final JsonWriter writer, @Nullable final T instance) { if (instance == null) { writer.writeNull(); } else if (alwaysSerialize) { writer.writeByte(JsonWriter.OBJECT_START); writeContentFull(writer, instance); writer.writeByte(JsonWriter.OBJECT_END); } else { writer.writeByte(JsonWriter.OBJECT_START); if (writeContentMinimal(writer, instance)) { writer.getByteBuffer()[writer.size() - 1] = JsonWriter.OBJECT_END; } else { writer.writeByte(JsonWriter.OBJECT_END); } } }
Example 3
Source File: BArrayJsonCodec.java From gridgo with MIT License | 6 votes |
@Override public void write(JsonWriter writer, BArray value) { if (value == null) { writer.writeNull(); return; } writer.writeByte(JsonWriter.ARRAY_START); final int size = value.size(); if (size > 0) { final Iterator<BElement> iterator = value.iterator(); compositeCodec.write(writer, iterator.next()); for (int i = 1; i < size; i++) { writer.writeByte(JsonWriter.COMMA); compositeCodec.write(writer, iterator.next()); } } writer.writeByte(JsonWriter.ARRAY_END); }
Example 4
Source File: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 6 votes |
private static void serializeStringKeyScalarValueMap(Iterator<? extends Map.Entry<String, ? /* String|Number|Boolean */>> it, StringBuilder replaceBuilder, JsonWriter jw, boolean extendedStringLimit, boolean supportsNonStringValues) { jw.writeByte(OBJECT_START); if (it.hasNext()) { Map.Entry<String, ?> kv = it.next(); writeStringValue(sanitizeLabelKey(kv.getKey(), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); serializeScalarValue(replaceBuilder, jw, kv.getValue(), extendedStringLimit, supportsNonStringValues); while (it.hasNext()) { jw.writeByte(COMMA); kv = it.next(); writeStringValue(sanitizeLabelKey(kv.getKey(), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); serializeScalarValue(replaceBuilder, jw, kv.getValue(), extendedStringLimit, supportsNonStringValues); } } jw.writeByte(OBJECT_END); }
Example 5
Source File: World.java From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void serialize(JsonWriter writer, boolean minimal) { writer.writeAscii("{\"id\":"); NumberConverter.serialize(this.id, writer); writer.writeAscii(",\"randomNumber\":"); NumberConverter.serialize(this.randomNumber, writer); writer.writeByte(com.dslplatform.json.JsonWriter.OBJECT_END); }
Example 6
Source File: MetricRegistrySerializer.java From apm-agent-java with Apache License 2.0 | 5 votes |
public static void serialize(Map<? extends Labels, MetricSet> metricSets, StringBuilder replaceBuilder, JsonWriter jw) { final long timestamp = System.currentTimeMillis() * 1000; for (MetricSet metricSet : metricSets.values()) { if (metricSet.hasContent()) { serializeMetricSet(metricSet, timestamp, replaceBuilder, jw); metricSet.onAfterReport(); jw.writeByte(NEW_LINE); } } }
Example 7
Source File: WriteDescription.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
public final void writeContentFull(final JsonWriter writer, @Nullable final T instance) { if (isEmpty) return; encoders[0].write(writer, instance); for (int i = 1; i < encoders.length; i++) { writer.writeByte(JsonWriter.COMMA); encoders[i].write(writer, instance); } }
Example 8
Source File: BObjectJsonCodec.java From gridgo with MIT License | 5 votes |
@Override public void write(JsonWriter writer, BObject value) { if (value == null) { writer.writeNull(); return; } writer.writeByte(JsonWriter.OBJECT_START); final int size = value.size(); if (size > 0) { final Iterator<Map.Entry<String, BElement>> iterator = value.entrySet().iterator(); Map.Entry<String, BElement> kv = iterator.next(); writer.writeString(kv.getKey()); writer.writeByte(JsonWriter.SEMI); compositeCodec.write(writer, kv.getValue()); for (int i = 1; i < size; i++) { kv = iterator.next(); var val = kv.getValue(); if ((val == null || val.isNullValue()) && this.compactMode == COMPACT) continue; writer.writeByte(JsonWriter.COMMA); writer.writeString(kv.getKey()); writer.writeByte(JsonWriter.SEMI); compositeCodec.write(writer, val); } } writer.writeByte(JsonWriter.OBJECT_END); }
Example 9
Source File: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 5 votes |
static void writeField(final String fieldName, @Nullable final CharSequence value, StringBuilder replaceBuilder, JsonWriter jw) { if (value != null) { writeFieldName(fieldName, jw); writeStringValue(value, replaceBuilder, jw); jw.writeByte(COMMA); } }
Example 10
Source File: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 5 votes |
private static void serialize(Labels labels, StringBuilder replaceBuilder, JsonWriter jw) { for (int i = 0; i < labels.size(); i++) { if (i > 0) { jw.writeByte(COMMA); } writeStringValue(sanitizeLabelKey(labels.getKey(i), replaceBuilder), replaceBuilder, jw); jw.writeByte(JsonWriter.SEMI); serializeScalarValue(replaceBuilder, jw, labels.getValue(i), false, false); } }
Example 11
Source File: ArrayFormatDescription.java From dsl-json with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void writeContentFull(final JsonWriter writer, @Nullable final T instance) { if (isEmpty) return; encoders[0].write(writer, instance); for (int i = 1; i < encoders.length; i++) { writer.writeByte(JsonWriter.COMMA); encoders[i].write(writer, instance); } }
Example 12
Source File: MetricRegistrySerializer.java From apm-agent-java with Apache License 2.0 | 5 votes |
private static void serializeValueStart(String key, String suffix, JsonWriter jw) { jw.writeByte(JsonWriter.QUOTE); jw.writeAscii(key); jw.writeAscii(suffix); jw.writeByte(JsonWriter.QUOTE); jw.writeByte(JsonWriter.SEMI); jw.writeByte(JsonWriter.OBJECT_START); jw.writeByte(JsonWriter.QUOTE); jw.writeAscii("value"); jw.writeByte(JsonWriter.QUOTE); jw.writeByte(JsonWriter.SEMI); }
Example 13
Source File: DslJsonSerializer.java From apm-agent-java with Apache License 2.0 | 4 votes |
public static void writeFieldName(final String fieldName, final JsonWriter jw) { jw.writeByte(JsonWriter.QUOTE); jw.writeAscii(fieldName); jw.writeByte(JsonWriter.QUOTE); jw.writeByte(JsonWriter.SEMI); }
Example 14
Source File: HexUtils.java From apm-agent-java with Apache License 2.0 | 4 votes |
private static void writeHexByte(JsonWriter jw, byte b) { int v = b & 0xFF; jw.writeByte((byte) hexArray[v >>> 4]); jw.writeByte((byte) hexArray[v & 0x0F]); }
Example 15
Source File: BReferenceJsonCodec.java From gridgo with MIT License | 4 votes |
private void tryWriteCommaAfterValue(JsonWriter writer, Stack<Integer> lengthStack, Stack<AtomicInteger> indexStack) { if (lengthStack.size() > 0 && indexStack.peek().incrementAndGet() < lengthStack.peek()) writer.writeByte(COMMA); }
Example 16
Source File: BReferenceJsonCodec.java From gridgo with MIT License | 4 votes |
private void tryWriteCommaAfterContainerEnd(JsonWriter writer, Stack<Integer> lengthStack, Stack<AtomicInteger> indexStack) { if (lengthStack.size() > 0 && lengthStack.peek() > indexStack.peek().get()) writer.writeByte(COMMA); }
Example 17
Source File: MetricRegistrySerializer.java From apm-agent-java with Apache License 2.0 | 4 votes |
private static void serializeValue(String key, String suffix, long value, JsonWriter jw) { serializeValueStart(key, suffix, jw); NumberConverter.serialize(value, jw); jw.writeByte(JsonWriter.OBJECT_END); }
Example 18
Source File: BReferenceCompactJsonCodec.java From gridgo with MIT License | 4 votes |
private void tryWriteComma(JsonWriter writer, AtomicBoolean waitingForComma) { if (waitingForComma.get()) writer.writeByte(COMMA); }
Example 19
Source File: MetricRegistrySerializer.java From apm-agent-java with Apache License 2.0 | 4 votes |
private static void serializeValue(String key, String suffix, double value, JsonWriter jw) { serializeValueStart(key, suffix, jw); NumberConverter.serialize(value, jw); jw.writeByte(JsonWriter.OBJECT_END); }
Example 20
Source File: MetricRegistrySerializer.java From apm-agent-java with Apache License 2.0 | 4 votes |
private static void serializeCounter(String key, AtomicLong value, JsonWriter jw) { serializeValueStart(key, "", jw); NumberConverter.serialize(value.get(), jw); jw.writeByte(JsonWriter.OBJECT_END); value.set(0); }