/** Encodes per ListOfSpans data wireType, where field one is repeated spans */ public byte[] writeList(List<Span> spans) { int lengthOfSpans = spans.size(); if (lengthOfSpans == 0) return EMPTY_ARRAY; if (lengthOfSpans == 1) return write(spans.get(0)); int sizeInBytes = 0; int[] sizeOfValues = new int[lengthOfSpans]; for (int i = 0; i < lengthOfSpans; i++) { int sizeOfValue = sizeOfValues[i] = SPAN.sizeOfValue(spans.get(i)); sizeInBytes += sizeOfLengthDelimitedField(sizeOfValue); } Buffer result = new Buffer(sizeInBytes); for (int i = 0; i < lengthOfSpans; i++) { writeSpan(spans.get(i), sizeOfValues[i], result); } return result.toByteArray(); }
byte[] write(Span onlySpan) { int sizeOfValue = SPAN.sizeOfValue(onlySpan); Buffer result = new Buffer(sizeOfLengthDelimitedField(sizeOfValue)); writeSpan(onlySpan, sizeOfValue, result); return result.toByteArray(); }