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

org.kafkacrypto.msgs.CryptoState Maven / Gradle / Ivy

Go to download

Java port of kafkacrypto, a lightweight and cross-platform/cross-language encryption library for Apache Kafka.

There is a newer version: 0.9.11.0
Show newest version
package org.kafkacrypto.msgs;

import org.msgpack.core.MessagePacker;
import org.msgpack.value.Value;
import java.util.List;
import java.util.Map;
import java.util.LinkedHashMap;

import java.io.IOException;

import org.kafkacrypto.msgs.msgpack;
import org.kafkacrypto.msgs.Msgpacker;
import org.kafkacrypto.msgs.EncryptionKeys;

public class CryptoState extends LinkedHashMap implements Msgpacker
{
  public CryptoState unpackb(List src) throws IOException
  {
    if (src == null || src.size() != 1 || !src.get(0).isMapValue()) return this;
    Map cryptostate = src.get(0).asMapValue().map();
    for (Value state : cryptostate.keySet())
      if (state.isStringValue() && cryptostate.get(state).isArrayValue())
        this.put(state.asStringValue().asString(), new EncryptionKeys().unpackb(cryptostate.get(state).asArrayValue().list()));
    return this;
  }

  public void packb(MessagePacker packer) throws IOException
  {
    packer.packMapHeader(this.size());
    for (String r : this.keySet()) {
      msgpack.packb_recurse(packer, r);
      msgpack.packb_recurse(packer, (Msgpacker)(this.get(r)));
    }
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy