public static byte[] convertRequestToCbor(HystrixRequestEvents request) throws IOException {
   ByteArrayOutputStream cborString = new ByteArrayOutputStream();
   CBORGenerator cbor = cborFactory.createGenerator(cborString);
   writeRequestAsCbor(cbor, request);
   cbor.flush();
   cbor.close();
   return cborString.toByteArray();
 }
 private static void writeRequestAsCbor(CBORGenerator cbor, HystrixRequestEvents request)
     throws IOException {
   cbor.writeStartArray();
   for (Map.Entry<HystrixRequestEvents.ExecutionSignature, List<Integer>> entry :
       request.getExecutionsMappedToLatencies().entrySet()) {
     convertExecutionToCbor(cbor, entry.getKey(), entry.getValue());
   }
   cbor.writeEndArray();
 }
 public static byte[] convertRequestsToCbor(Collection<HystrixRequestEvents> requests)
     throws IOException {
   ByteArrayOutputStream cborString = new ByteArrayOutputStream();
   CBORGenerator cbor = cborFactory.createGenerator(cborString);
   cbor.writeStartArray();
   for (HystrixRequestEvents request : requests) {
     writeRequestAsCbor(cbor, request);
   }
   cbor.writeEndArray();
   cbor.close();
   return cborString.toByteArray();
 }
 private static void convertExecutionToCbor(
     CBORGenerator cbor,
     HystrixRequestEvents.ExecutionSignature executionSignature,
     List<Integer> latencies)
     throws IOException {
   cbor.writeStartObject();
   cbor.writeStringField(NAME_FIELD, executionSignature.getCommandName());
   cbor.writeArrayFieldStart(EVENTS_FIELD);
   ExecutionResult.EventCounts eventCounts = executionSignature.getEventCounts();
   for (HystrixEventType eventType : HystrixEventType.values()) {
     if (eventType.equals(COLLAPSED)) {
       cbor.writeNumber(eventType.ordinal());
       cbor.writeNumber(executionSignature.getCollapserBatchSize());
       continue;
     }
     if (eventCounts.contains(eventType)) {
       int eventCount = eventCounts.getCount(eventType);
       if (eventCount > 0) {
         cbor.writeNumber(eventType.ordinal());
         cbor.writeNumber(eventCount);
       }
     }
   }
   cbor.writeEndArray();
   cbor.writeArrayFieldStart(LATENCIES_FIELD);
   for (int latency : latencies) {
     cbor.writeNumber(latency);
   }
   cbor.writeEndArray();
   if (executionSignature.getCachedCount() > 0) {
     cbor.writeNumber(executionSignature.getCachedCount());
   }
   cbor.writeEndObject();
 }