All Downloads are FREE. Search and download functionalities are using the official Maven repository.

it.auties.protobuf.tool.command.DecodeCommand Maven / Gradle / Ivy

The newest version!
package it.auties.protobuf.tool.command;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import it.auties.protobuf.api.jackson.ProtobufMapper;
import it.auties.protobuf.tool.util.RawProtobufConverter;
import lombok.extern.log4j.Log4j2;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;

import java.io.IOException;
import java.util.Map;
import java.util.concurrent.Callable;

@Log4j2
@Command(
        name = "decode",
        mixinStandardHelpOptions = true,
        version = "decode 1.0",
        description = "Decodes a protobuf message encoded as binary data"
)
public class DecodeCommand implements Callable {
    private static final ObjectMapper JACKSON = new ProtobufMapper();

    @SuppressWarnings("FieldMayBeFinal")
    @Parameters(
            index = "0",
            converter = RawProtobufConverter.class,
            description = "The protobuf message to decode, can be an array of bytes or an hex string"
    )
    private byte[] protobuf = null;

    @Override
    public Integer call() {
        try {
            var result = JACKSON.readValue(protobuf,
                    new TypeReference>() {
                    });
            log.info(result);
            return 0;
        } catch (IOException ex) {
            log.info("Cannot parse Protobuf message");
            log.throwing(ex);
            return -1;
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy