Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ default_steps: &default_steps

- run: |
mvn clean install
- run: cd dogstatsd-http-serializer && mvn clean install

jobs:
openjdk7:
Expand Down
1 change: 1 addition & 0 deletions dogstatsd-http-serializer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/target/
100 changes: 100 additions & 0 deletions dogstatsd-http-serializer/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.datadoghq</groupId>
<artifactId>dogstatsd-http-serializer</artifactId>
<packaging>jar</packaging>
<name>dogstatsd-http-serializer</name>
<version>1.0.0-SNAPSHOT</version>
<description>HTTP serializer for DogStatsD metrics.</description>
<url>https://github.com/DataDog/java-dogstatsd-client</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<licenses>
<license>
<name>The MIT License (MIT)</name>
<url>http://opensource.org/licenses/MIT</url>
<distribution>repo</distribution>
</license>
</licenses>

<scm>
<url>https://github.com/DataDog/java-dogstatsd-client</url>
<connection>scm:git:git@github.com:DataDog/java-dogstatsd-client.git</connection>
<developerConnection>scm:git:git@github.com:Datadog/java-dogstatsd-client.git</developerConnection>
</scm>

<developers>
<developer>
<id>datadog</id>
<name>Datadog developers</name>
<email>dev@datadoghq.com</email>
</developer>
</developers>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<profiles>
<profile>
<id>spotless</id>
<activation>
<jdk>[17.0,)</jdk>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.45.0</version>
<configuration>
<java>
<googleJavaFormat>
<version>1.28.0</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Unless explicitly stated otherwise all files in this repository are
* licensed under the Apache 2.0 License.
*
* This product includes software developed at Datadog
* (https://www.datadoghq.com/) Copyright 2026 Datadog, Inc.
*/

package com.datadoghq.dogstatsd.http.serializer;

import java.nio.BufferOverflowException;

abstract class Buffer {
protected int size;

// more must be >= 0.
// if this returns, size + more <= INT_MAX && size + more <= data.length
protected final void reserve(int more) {
// size + more > capacity, but without integer overflow
if (size > capacity() - more) {
grow(more);
}
}

protected final void grow(int more) {
if (size > Integer.MAX_VALUE - more) {
throw new BufferOverflowException();
}
int newSize = size + more;
int cap = capacity();
if (cap < Integer.MAX_VALUE / 2 && newSize < cap * 2) {
newSize = cap * 2;
}
realloc(newSize);
}

int length() {
return size;
}

void clear() {
size = 0;
}

/** Return true if buf is null or empty */
static boolean isEmpty(Buffer buf) {
return buf == null || buf.size == 0;
}

abstract int capacity();

protected abstract void realloc(int newSize);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/* Unless explicitly stated otherwise all files in this repository are
* licensed under the Apache 2.0 License.
*
* This product includes software developed at Datadog
* (https://www.datadoghq.com/) Copyright 2026 Datadog, Inc.
*/

package com.datadoghq.dogstatsd.http.serializer;

import java.util.Arrays;

class ByteBuffer extends Buffer {
byte[] data;

ByteBuffer() {
data = new byte[64];
}

ByteBuffer(int cap) {
data = new byte[cap];
}

void put(byte v) {
reserve(1);
data[size++] = v;
}

void put(byte[] vs, int length) {
reserve(length);
System.arraycopy(vs, 0, data, size, length);
size += length;
}

void put(byte[] vs) {
put(vs, vs.length);
}

void put(ByteBuffer buf) {
put(buf.data, buf.size);
}

void putFixed32(int v) {
put((byte) v);
put((byte) (v >>> 8));
put((byte) (v >>> 16));
put((byte) (v >>> 24));
}

void putFixed64(long v) {
put((byte) v);
put((byte) (v >>> 8));
put((byte) (v >>> 16));
put((byte) (v >>> 24));
put((byte) (v >>> 32));
put((byte) (v >>> 40));
put((byte) (v >>> 48));
put((byte) (v >>> 56));
}

void putFloat32(float v) {
putFixed32(Float.floatToRawIntBits(v));
}

void putFloat64(double v) {
putFixed64(Double.doubleToRawLongBits(v));
}

void putUint64(long v) {
do {
put((byte) (v & 127 | (v > 127 ? 128 : 0)));
v >>>= 7;
} while (v != 0);
}

void putSint64(long v) {
putUint64((v >> 63) ^ (v << 1));
}

void putBytesFieldHeader(int id, int len) {
putUint64(ProtoUtil.bytesFieldHeader(id));
putUint64(len);
}

void putBytesField(int id, ByteBuffer data) {
putBytesFieldHeader(id, data.length());
put(data);
}

@Override
int capacity() {
return data.length;
}

@Override
protected void realloc(int newSize) {
data = Arrays.copyOf(data, newSize);
}

byte[] toArray() {
if (size == data.length) {
return data;
}
return Arrays.copyOf(data, size);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Unless explicitly stated otherwise all files in this repository are
* licensed under the Apache 2.0 License.
*
* This product includes software developed at Datadog
* (https://www.datadoghq.com/) Copyright 2026 Datadog, Inc.
*/

package com.datadoghq.dogstatsd.http.serializer;

enum Column {
dictNameStr(1),
dictTagStr(2),
dictTagsets(3),
dictResourceStr(4),
dictResourceLen(5),
dictResourceType(6),
dictResourceName(7),
dictSourceTypeName(8),
dictOriginInfo(9),
types(10),
nameRefs(11),
tagsetRefs(12),
resourcesRefs(13),
intervals(14),
numPoints(15),
timestamps(16),
valsSint64(17),
valsFloat32(18),
valsFloat64(19),
sketchNumBins(20),
sketchBinKeys(21),
sketchBinCnts(22),
sourceTypeNameRefs(23),
originInfoRefs(24);

static final int MAX = 24;

final int id;

Column(int id) {
this.id = id;
}
}
Loading