/*
 * Copyright 2013-2017 Spotify AB. All rights reserved.
 *
 * The contents of this file are licensed under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.spotify.ffwd.kafka;

import kafka.serializer.Encoder;
import kafka.utils.VerifiableProperties;

public class IntegerEncoder implements Encoder<Integer> {
    public IntegerEncoder(VerifiableProperties properties) {
    }

    @Override
    public byte[] toBytes(Integer o) {
        final int i = o;
        return new byte[]{
            (byte) (i & 0xff), (byte) ((i << 8) & 0xff), (byte) ((i << 16) & 0xff),
            (byte) ((i << 24) & 0xff)
        };
    }
}

/*-
 * -\-\-
 * FastForward Kafka Module
 * --
 * Copyright (C) 2016 - 2018 Spotify AB
 * --
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * -/-/-
 */

package com.spotify.ffwd.kafka;

import kafka.serializer.Encoder;
import kafka.utils.VerifiableProperties;

public class IntegerEncoder implements Encoder<Integer> {
    public IntegerEncoder(VerifiableProperties properties) {
    }

    @Override
    public byte[] toBytes(Integer o) {
        final int i = o;
        return new byte[]{
            (byte) (i & 0xff), (byte) ((i << 8) & 0xff), (byte) ((i << 16) & 0xff),
            (byte) ((i << 24) & 0xff)
        };
    }
}

update license header